There was an error while loading. Please reload this page.
BRANCH_LEFT
BRANCH_RIGHT
1 parent 438cbd8 commit d18f73aCopy full SHA for d18f73a
2 files changed
Lib/test/test_monitoring.py
@@ -3,6 +3,7 @@
3
import collections
4
import dis
5
import functools
6
+import inspect
7
import math
8
import operator
9
import sys
@@ -1709,6 +1710,27 @@ def func(v=1):
1709
1710
('branch right', 'func', 6, 8),
1711
('branch right', 'func', 2, 10)])
1712
1713
+ def test_callback_set_frame_lineno(self):
1714
+ def func(s: str) -> int:
1715
+ if s.startswith("t"):
1716
+ return 1
1717
+ else:
1718
+ return 0
1719
+
1720
+ def callback(code, from_, to):
1721
+ # try set frame.f_lineno
1722
+ frame = inspect.currentframe()
1723
+ while frame and frame.f_code is not code:
1724
+ frame = frame.f_back
1725
1726
+ self.assertIsNotNone(frame)
1727
+ frame.f_lineno = frame.f_lineno + 1 # run next instruction
1728
1729
+ sys.monitoring.set_local_events(TEST_TOOL, func.__code__, E.BRANCH_LEFT)
1730
+ sys.monitoring.register_callback(TEST_TOOL, E.BRANCH_LEFT, callback)
1731
1732
+ self.assertEqual(func("true"), 1)
1733
1734
1735
class TestBranchConsistency(MonitoringTestBase, unittest.TestCase):
1736
Objects/frameobject.c
@@ -1685,6 +1685,8 @@ frame_lineno_set_impl(PyFrameObject *self, PyObject *value)
1685
case PY_MONITORING_EVENT_PY_RESUME:
1686
case PY_MONITORING_EVENT_JUMP:
1687
case PY_MONITORING_EVENT_BRANCH:
1688
+ case PY_MONITORING_EVENT_BRANCH_LEFT:
1689
+ case PY_MONITORING_EVENT_BRANCH_RIGHT:
1690
case PY_MONITORING_EVENT_LINE:
1691
case PY_MONITORING_EVENT_PY_YIELD:
1692
/* Setting f_lineno is allowed for the above events */
0 commit comments