Inspect library ignore comments at the end of a function (inspect.getsource) #86282
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee = None closed_at = <Date 2020-12-04.20:21:43.707> created_at = <Date 2020-10-22.10:48:43.969> labels = ['3.8', 'type-feature', 'library', '3.9', '3.10'] title = 'Inspect library ignore comments at the end of a function (inspect.getsource)' updated_at = <Date 2020-12-15.13:21:15.932> user = 'https://bugs.python.org/noureddinehamid'
activity = <Date 2020-12-15.13:21:15.932> actor = 'iritkatriel' assignee = 'none' closed = True closed_date = <Date 2020-12-04.20:21:43.707> closer = 'taleinat' components = ['Library (Lib)'] creation = <Date 2020-10-22.10:48:43.969> creator = 'noureddine.hamid' dependencies =  files =  hgrepos =  issue_num = 42116 keywords = ['patch'] message_count = 9.0 messages = ['379289', '382416', '382417', '382505', '382526', '382527', '382528', '383047', '383054'] nosy_count = 6.0 nosy_names = ['taleinat', 'yselivanov', 'miss-islington', 'BTaskaya', 'iritkatriel', 'noureddine.hamid'] pr_nums = ['23630', '23643', '23644'] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue42116' versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']
The text was updated successfully, but these errors were encountered:
inspect.getsource ignore comments at the end of the function:
for example this function: def matmul_single(A, x, out): from numpy import matmul out[:] = matmul(A, x) # Some comment here...
using the inspect library: >>> inspect.getsource(matmul_single) >>> "def omp_matmul_single(A, x, out):\n from numpy import matmul\n out[:] = matmul(A, x)\n"
the result does not contain the comments at the end of the function.
PR 23630 aims to include comment lines in the block if their start column is after the start column of the opening line of the block:
def f(): return 42
# this is not a part of f
For reference - this script:
import inspect import tokenize from pprint import pprint as pp src=[ 'def f():\n', ' return 1\n', ' #that was fun', '\n', '#Now comes g\n', 'def g():\n', ' return 2\n']