diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index 3f902b1fe74ce8..dd4418dd98b22a 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -602,6 +602,23 @@ def run(tracer): self.compare_events(doit_async.__code__.co_firstlineno, tracer.events, events) + def test_loop_in_try_except(self): + # https://bugs.python.org/issue41670 + + def func(): + try: + for i in []: pass + return 1 + except: + return 2 + + self.run_and_compare(func, + [(0, 'call'), + (1, 'line'), + (2, 'line'), + (3, 'line'), + (3, 'return')]) + class SkipLineEventsTraceTestCase(TraceTestCase): """Repeat the trace tests, but with per-line events skipped""" diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst new file mode 100644 index 00000000000000..6ad5fb6dc9bb40 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst @@ -0,0 +1,4 @@ +Prevent line trace being skipped on platforms not compiled +with ``USE_COMPUTED_GOTOS``. +Fixes issue where some lines nested within a try-except block +were not being traced on Windows. diff --git a/Python/ceval.c b/Python/ceval.c index f747faaebf024a..d29e135a64d0cf 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2297,7 +2297,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag) } case TARGET(POP_BLOCK): { - PREDICTED(POP_BLOCK); PyFrame_BlockPop(f); DISPATCH(); } @@ -3352,7 +3351,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag) STACK_SHRINK(1); Py_DECREF(iter); JUMPBY(oparg); - PREDICT(POP_BLOCK); DISPATCH(); }