[issue14483] inspect.getsource fails to read a file of only comments

R. David Murray report at bugs.python.org
Fri Dec 23 14:22:23 EST 2016


R. David Murray added the comment:

Well, there's nobody being paid for keeping track of bugs and responding, so things do slip through the cracks.  Pinging an issue after there's been a lack of response for a while is appropriate, if you notice it yourself :)  (Mark, while he was trying to be helpful, does not speak for the Python community.)

As far as the question of is this intentional, the answer is yes.  Presumably you are calling it on the 'main' function.  If you call it on the module, you will get all source lines from that module.  (You can't call it "on the file", the argument must be an object.)

You'll see why it is intentional for the 'main' case if you consider that while in Python whitespace is syntactically significant, this is *not* true for Python comments indentation, because comments are treated as if they *are* whitespace.  getsourcelines stops looking at sourcelines on the last line recorded in the lnotab for that function, so any subsequent comments are not considered part of the function.

So, I'm closing this as "not a bug" since it works as expected for me in both python 2.7 and 3.6.

Thanks for waking the issue up, Pam.  You have contributed to python by getting an open issue closed, but you'll have to find something else to work on during the break I'm afraid.

----------
nosy: +r.david.murray
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list