Message399003
Note: this is very similar to https://bugs.python.org/issue42810
This was originally reported against coverage.py: https://github.com/nedbat/coveragepy/issues/1205
---8<-------------
import linecache, sys
def trace(frame, event, arg):
# The weird globals here is to avoid a NameError on shutdown...
if frame.f_code.co_filename == globals().get("__file__"):
lineno = frame.f_lineno
print("{} {}: {}".format(event[:4], lineno, linecache.getline(__file__, lineno).rstrip()))
return trace
print(sys.version)
sys.settrace(trace)
def func():
if A:
if B:
if C:
if D:
return False
else:
return False
elif E and F:
return True
A = B = True
C = False
func()
-------------------------
This produces this trace output:
3.10.0rc1 (default, Aug 3 2021, 15:03:55) [Clang 12.0.0 (clang-1200.0.32.29)]
call 13: def func():
line 14: if A:
line 15: if B:
line 16: if C:
line 21: elif E and F:
retu 21: elif E and F:
The elif on line 21 is not executed, and should not be traced.
Also, if I change line 21 to `elif E:`, then the trace changes to:
3.10.0rc1 (default, Aug 3 2021, 15:03:55) [Clang 12.0.0 (clang-1200.0.32.29)]
call 13: def func():
line 14: if A:
line 15: if B:
line 16: if C:
line 22: return True
retu 22: return True |
|
Date |
User |
Action |
Args |
2021-08-05 13:11:40 | nedbat | set | recipients:
+ nedbat, Mark.Shannon |
2021-08-05 13:11:40 | nedbat | set | messageid: <1628169100.37.0.353483963834.issue44840@roundup.psfhosted.org> |
2021-08-05 13:11:40 | nedbat | link | issue44840 messages |
2021-08-05 13:11:40 | nedbat | create | |
|