gh-89726 handle frame.f_lineno is None in inspect.getframeinfo#32044
Draft
graingert wants to merge 2 commits intopython:mainfrom
Draft
gh-89726 handle frame.f_lineno is None in inspect.getframeinfo#32044graingert wants to merge 2 commits intopython:mainfrom
graingert wants to merge 2 commits intopython:mainfrom
Conversation
graingert
commented
Mar 22, 2022
Lib/inspect.py
Outdated
Contributor
Author
There was a problem hiding this comment.
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
0354393 to
387b376
Compare
Member
|
What are you trying to fix here? |
387b376 to
0fd59f0
Compare
Contributor
Author
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()) |
Member
|
I would make more sense IMO to fix inspect to not crash, rather than trying to fake a line number. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://bugs.python.org/issue45563