Skip to content

Commit b49f95d

Browse files
committed
set lineno for frame 1
1 parent 2e4db16 commit b49f95d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Lib/test/test_monitoring.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import collections
44
import dis
55
import functools
6+
import inspect
67
import math
78
import operator
89
import sys
@@ -1717,10 +1718,15 @@ def func(s: str) -> int:
17171718
return 0
17181719

17191720
def callback(code, from_, to):
1720-
frame = sys._getframe(0)
1721-
old = frame.f_lineno
1722-
# try set frame.f_lineno
1723-
frame.f_lineno = frame.f_lineno
1721+
frame = inspect.currentframe()
1722+
while frame and frame.f_code is not code:
1723+
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
17241730

17251731
sys.monitoring.set_local_events(TEST_TOOL, func.__code__, E.BRANCH_LEFT)
17261732
sys.monitoring.register_callback(TEST_TOOL, E.BRANCH_LEFT, callback)

0 commit comments

Comments
 (0)