-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
inspect.getframeinfo() cannot show first line #60016
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
Comments
When inspect.getframeinfo() tries to collect lines of context it never shows the first line (unless context is as big as the number of lines in the file). The relevant code is start = lineno - 1 - context//2
try:
lines, lnum = findsource(frame)
except IOError:
lines = index = None
else:
--> start = max(start, 1)
start = max(0, min(start, len(lines) - context))
lines = lines[start:start+context]
index = lineno - 1 - start I think that start = max(start, 1) should be replaced by start = max(start, 0) For some reason getframeinfo() (and the functions which use it) don't seem to be tested by the testsuite... |
Looking into this now. Should have a patch either later today or tommorow. |
Also, would you mind posting an example? I'm having trouble replicating. |
Nevermind, replicated it. Changing start = max(start, 1) to start = max(start, 0) DOES fix. Writing a test case now. |
Here's a patch. Very, very simple, just changed that one line in inspect.py and wrote a highly primitive test case for inspect.getframeinfo. The test isn't actually testing the primary functionality right now, just this one bug. I can probably write more expansive coverage later, but in the interest of an expeditious reply I'm submitting now. |
I have just hit this bug and independently invented the exact fix of changing the zero for a one. Any chance of getting this merged? |
New changeset 15454cad5f27 by Berker Peksag in branch '3.5': New changeset 410caf255a09 by Berker Peksag in branch '3.6': New changeset 803c3c21c3bc by Berker Peksag in branch 'default': |
Thanks for the patch Sam and thanks for the ping Peter! |
start is bounded to 0 twice. start = max(start, 0)
start = max(0, min(start, len(lines) - context)) The first line can be just removed. Or two above lines can be rewritten as: start = min(start, len(lines) - context)
start = max(start, 0) |
New changeset 2b6bdd6cd3f8 by Berker Peksag in branch '3.5': New changeset 7cbcee0c53e3 by Berker Peksag in branch '3.6': New changeset 5b0dee884b0b by Berker Peksag in branch 'default': |
You're right. Thanks for the review, Serhiy! |
Misc/NEWS
so that it is managed by towncrier #552Note: 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: