We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2e4db16 commit b49f95dCopy full SHA for b49f95d
1 file 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
@@ -1717,10 +1718,15 @@ def func(s: str) -> int:
1717
1718
return 0
1719
1720
def callback(code, from_, to):
- frame = sys._getframe(0)
1721
- old = frame.f_lineno
1722
- # try set frame.f_lineno
1723
- frame.f_lineno = frame.f_lineno
+ frame = inspect.currentframe()
+ while frame and frame.f_code is not code:
+ frame = frame.f_back
1724
+
1725
+ if frame:
1726
+ self.assertIs(frame.f_code, code)
1727
+ # try get and set frame.f_lineno
1728
+ l = frame.f_lineno
1729
+ frame.f_lineno = l
1730
1731
sys.monitoring.set_local_events(TEST_TOOL, func.__code__, E.BRANCH_LEFT)
1732
sys.monitoring.register_callback(TEST_TOOL, E.BRANCH_LEFT, callback)
0 commit comments