New submission from Ned Batchelder <n...@nedbatchelder.com>:
(from https://github.com/nedbat/coveragepy/issues/1184) This code runs the return statement on line 17 twice. The second time, there is a "line" event and then a "return" event for that line. But the first time, there is only a "return" event: --- 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 foo(x): if x: try: 1/(x - 1) except ZeroDivisionError: pass return x def test_foo(): for i in range(2): foo(i) print(sys.version) sys.settrace(trace) test_foo() ----------------------------------------- I get this output with 3.10.0b3: 3.10.0b3 (default, Jun 18 2021, 06:43:38) [Clang 12.0.0 (clang-1200.0.32.29)] call 19: def test_foo(): line 20: for i in range(2): line 21: foo(i) call 10: def foo(x): line 11: if x: retu 17: return x line 20: for i in range(2): line 21: foo(i) call 10: def foo(x): line 11: if x: line 12: try: line 13: 1/(x - 1) exce 13: 1/(x - 1) line 14: except ZeroDivisionError: line 15: pass line 17: return x retu 17: return x line 20: for i in range(2): retu 20: for i in range(2): Shouldn't there be a "line" event for both invocations? ---------- components: Interpreter Core keywords: 3.10regression messages: 397024 nosy: Mark.Shannon, nedbat priority: normal severity: normal status: open title: 3.10.0b3 doesn't trace line events for return in some cases versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44570> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com