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
add test
  • Loading branch information
xuantengh committed Jul 30, 2025
commit 2e4db16adf480bffd9a2afaa77b71bafaa2756b8
18 changes: 18 additions & 0 deletions Lib/test/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,24 @@ def func(v=1):
('branch right', 'func', 6, 8),
('branch right', 'func', 2, 10)])

def test_callback_set_frame_lineno(self):
def func(s: str) -> int:
if s.startswith("t"):
return 1
else:
return 0

def callback(code, from_, to):
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)

self.assertEqual(func("true"), 1)


class TestBranchConsistency(MonitoringTestBase, unittest.TestCase):

Expand Down
Loading