-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inspect library ignore comments at the end of a function (inspect.getsource) #86282
Comments
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'] pp(list(tokenize.generate_tokens(iter(src).__next__))) Outputs: |
Thank you for reporting this, Noureddine Hamid! Thanks for the PR, Irit! |
thank you for the fix, I forgot to mention that python 3.6 and python 3.7 have this issue too. |
Thanks for the report. 3.6 is no longer maintained and 3.7 is getting security fixes only. So this won't be backported to those versions. |
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
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: