Skip to content

gh-137200: support frame lineno setter with BRANCH_LEFT and BRANCH_RIGHT events #137229

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

Merged
merged 5 commits into from
Jul 31, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "set lineno for frame 1"
This reverts commit b49f95d.
  • Loading branch information
xuantengh committed Jul 31, 2025
commit d41cf781db89933235f20a8dd051d4b20045fad4
14 changes: 4 additions & 10 deletions Lib/test/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import collections
import dis
import functools
import inspect
import math
import operator
import sys
Expand Down Expand Up @@ -1718,15 +1717,10 @@ def func(s: str) -> int:
return 0

def callback(code, from_, to):
frame = inspect.currentframe()
while frame and frame.f_code is not code:
frame = frame.f_back

if frame:
self.assertIs(frame.f_code, code)
# try get and set frame.f_lineno
l = frame.f_lineno
frame.f_lineno = l
frame = sys._getframe(0)
old = frame.f_lineno
# try set frame.f_lineno
frame.f_lineno = frame.f_lineno

sys.monitoring.set_local_events(TEST_TOOL, func.__code__, E.BRANCH_LEFT)
sys.monitoring.register_callback(TEST_TOOL, E.BRANCH_LEFT, callback)
Expand Down