New submission from Ned Batchelder <n...@nedbatchelder.com>:
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? ---------- components: Interpreter Core messages: 397791 nosy: Mark.Shannon, nedbat priority: normal severity: normal status: open title: Final "pass" is traced incorrectly in 3.9 (and before) type: behavior versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44672> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com