-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-89726 handle frame.f_lineno is None in inspect.getframeinfo #32044
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
base: main
Are you sure you want to change the base?
Conversation
Lib/inspect.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a lasti2lineno implementation here - but it uses a reversed list(dis.finelinestarts(code)) and starts at 0 instead of co_firstlineno
Lines 119 to 126 in deeaac4
| def lasti2lineno(code, lasti): | |
| linestarts = list(dis.findlinestarts(code)) | |
| linestarts.reverse() | |
| for i, lineno in linestarts: | |
| if lasti >= i: | |
| return lineno | |
| return 0 | |
0354393 to
387b376
Compare
|
What are you trying to fix here? |
387b376 to
0fd59f0
Compare
frame can sometimes have a import sys
import inspect
def demo():
for i in range(1):
if i >= 0:
pass
class Tracer:
def __init__(self):
self.events = []
def trace(self, frame, event, arg):
inspect.getframeinfo(frame)
frame.f_trace_lines = True
frame.f_trace_opcodes = True
return self.trace
def main():
t = Tracer()
old_trace = sys.gettrace()
try:
sys.settrace(t.trace)
demo()
finally:
sys.settrace(old_trace)
if __name__ == "__main__":
sys.exit(main()) |
|
I would make more sense IMO to fix inspect to not crash, rather than trying to fake a line number. |
https://bugs.python.org/issue45563