Message397791
A simple function with a last "pass" statement gets traced incorrectly, attributing the return to the pass instead of the actual last statement executed:
--- 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
def wrong_loop(x):
if x:
if x:
print(4)
else:
pass
print(sys.version)
sys.settrace(trace)
wrong_loop(8)
----------------------------------
On 3.9 and before, this produces:
3.9.5 (default, May 5 2021, 06:50:43)
[Clang 12.0.0 (clang-1200.0.32.29)]
call 10: def wrong_loop(x):
line 11: if x:
line 12: if x:
line 13: print(4)
4
line 15: pass
retu 15: pass
Partly I'm writing this issue to record the problem, but partly to get a decision: will there be fixes made to 3.9 (or before) for issues like this? |
|
Date |
User |
Action |
Args |
2021-07-19 12:03:13 | nedbat | set | recipients:
+ nedbat, Mark.Shannon |
2021-07-19 12:03:13 | nedbat | set | messageid: <1626696193.12.0.565896913641.issue44672@roundup.psfhosted.org> |
2021-07-19 12:03:13 | nedbat | link | issue44672 messages |
2021-07-19 12:03:12 | nedbat | create | |
|