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

2017-02-23 Thread Aivar Annamaa

Aivar Annamaa added the comment:

Looks like I misinderstood inspect.findsource. I thought it is supposed to give 
only the code for argument object (eg. only def code when given a function), 
but looks like it is giving the whole file.

Unfortunately inspect.findsource is not documented in 
https://docs.python.org/3/library/inspect.html and inspect.getsource can't be 
used as replacement, because it doesn't work with modules.

--
stage:  -> resolved
status: open -> closed
versions: +Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-23 Thread Louie Lu

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2017-02-21 Thread Emily Morehouse

Changes by Emily Morehouse :


--
nosy: +emilyemorehouse

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-09-13 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +yselivanov

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-09-13 Thread Aivar Annamaa

Changes by Aivar Annamaa :


--
components: +Interpreter Core
type:  -> behavior
versions: +Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-09-13 Thread Aivar Annamaa

New submission from Aivar Annamaa:

Following program shows that frame.f_code.co_firstlineno ignores first line if 
it is a comment (or empty line), but inspect.getsource(frame.f_code) returns 
also the first line:

# first line
import inspect
frame = inspect.currentframe()
print(frame.f_code.co_firstlineno)
print(inspect.findsource(frame.f_code))

--
messages: 276211
nosy: Aivar.Annamaa
priority: normal
severity: normal
status: open
title: If module starts with comment or empty line then 
frame.f_code.co_firstlineno is inconsistent with inspect.findsource

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com