File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 3
3
import collections
4
4
import dis
5
5
import functools
6
+ import inspect
6
7
import math
7
8
import operator
8
9
import sys
@@ -1717,10 +1718,15 @@ def func(s: str) -> int:
1717
1718
return 0
1718
1719
1719
1720
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
1724
1730
1725
1731
sys .monitoring .set_local_events (TEST_TOOL , func .__code__ , E .BRANCH_LEFT )
1726
1732
sys .monitoring .register_callback (TEST_TOOL , E .BRANCH_LEFT , callback )
You can’t perform that action at this time.
0 commit comments