[issue28121] If module starts with comment or empty line then frame.f_code.co_firstlineno is inconsistent with inspect.findsource

Louie Lu report at bugs.python.org
Thu Feb 23 03:44:20 EST 2017


Louie Lu added the comment:

Sorry, but I can't reproduce at 3.7, 3.5, or 2.7.
the result shows me that inspect does respect comment line.

➜  cpython git:(350) ✗ ./python /tmp/main.py
2
(['# First line\n', 'import inspect\n', 'frame = inspect.currentframe()\n', 'print(frame.f_code.co_firstlineno)\n', 'print(inspect.findsource(frame.f_code))\n'], 0)

➜  /tmp python2 main.py
2
(['# First line\n', 'import inspect\n', 'frame = inspect.currentframe()\n', 'print(frame.f_code.co_firstlineno)\n', 'print(inspect.findsource(frame.f_code))\n'], 0)

----------
nosy: +louielu

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28121>
_______________________________________


More information about the Python-bugs-list mailing list