-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Incorrect frame.f_lineno when frame.f_trace is set #86989
Comments
The logic for frame.f_lineno assumes that the internal C field will be updated when f_trace is set, but that is incorrect. import sys
def print_line():
print(sys._getframe(1).f_lineno)
def test():
print_line()
sys._getframe(0).f_trace = True
print_line()
print_line()
test() prints it should print Fixing this is required by PEP-626, but it should be fixed anyway. |
This change seems like it has caused a problem. Python trace functions behave as they did in Python 3.9, but C trace functions no longer get line numbers for call or return events. Running this test code: def gen(inp):
for n in inp:
yield n
list(gen([1,2,3])) With my C trace function logging what it is passed, in Python 3.9 I got this:
With 3.10 (commit 1a9f51e) I get:
All of the call and return events now get a frame with f_lineno == 0. Python trace functions seem unaffected. The C code producing this debug output is here: https://github.com/nedbat/coveragepy/blob/a498ebc28273fd21b6a047a173b2e4443b91f563/coverage/ctracer/tracer.c#L786-L813 |
It looks like you are accessing the c field "f_lineno" directly. In the interest of efficiency it makes sense that the internal f_line field is updated before CALL and RETURN trace events. |
OK, thanks. I guess the parallels between the Python frame object and the C frame object made it easy to think I could use the fields directly. I'm updating the coverage.py code. |
Ned, can I close this? |
Note: 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: