From: Mark Shannon Date: Fri, 19 Nov 2021 15:16:49 +0000 (+0000) Subject: bpo-45709: Fix tracing when exception is handled. (GH-29638) X-Git-Tag: v3.11.0a3~211 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=337cb480e9dc1d27594ebd87a0045d00ec8b1c3a;p=thirdparty%2FPython%2Fcpython.git bpo-45709: Fix tracing when exception is handled. (GH-29638) --- diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index 3fe0bb7f460b..b565bef4c442 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -1137,6 +1137,38 @@ class TraceTestCase(unittest.TestCase): (7, 'line'), (7, 'return')]) + def test_tracing_exception_raised_in_with(self): + + class NullCtx: + def __enter__(self): + return self + def __exit__(self, *excinfo): + pass + + def func(): + try: + with NullCtx(): + 1/0 + except ZeroDivisionError: + pass + + self.run_and_compare(func, + [(0, 'call'), + (1, 'line'), + (2, 'line'), + (-5, 'call'), + (-4, 'line'), + (-4, 'return'), + (3, 'line'), + (3, 'exception'), + (2, 'line'), + (-3, 'call'), + (-2, 'line'), + (-2, 'return'), + (4, 'line'), + (5, 'line'), + (5, 'return')]) + class SkipLineEventsTraceTestCase(TraceTestCase): """Repeat the trace tests, but with per-line events skipped""" diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-11-19-13-17-47.bpo-45709.H_t7ut.rst b/Misc/NEWS.d/next/Core and Builtins/2021-11-19-13-17-47.bpo-45709.H_t7ut.rst new file mode 100644 index 000000000000..e3b007048cd6 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-11-19-13-17-47.bpo-45709.H_t7ut.rst @@ -0,0 +1,2 @@ +Restore behavior from 3.10 when tracing an exception raised within a with +statement. diff --git a/Python/ceval.c b/Python/ceval.c index 9d3ff74bace6..9e56b50ee844 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5093,10 +5093,7 @@ exception_unwind: JUMPTO(handler); /* Resume normal execution */ frame->f_state = FRAME_EXECUTING; - frame->f_lasti = handler; - NEXTOPARG(); - PRE_DISPATCH_GOTO(); - DISPATCH_GOTO(); + DISPATCH(); } exiting: