]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45709: Fix tracing when exception is handled. (GH-29638)
authorMark Shannon <mark@hotpy.org>
Fri, 19 Nov 2021 15:16:49 +0000 (15:16 +0000)
committerGitHub <noreply@github.com>
Fri, 19 Nov 2021 15:16:49 +0000 (15:16 +0000)
Lib/test/test_sys_settrace.py
Misc/NEWS.d/next/Core and Builtins/2021-11-19-13-17-47.bpo-45709.H_t7ut.rst [new file with mode: 0644]
Python/ceval.c

index 3fe0bb7f460b9a7af94e771f2b11b7d0c0cb05fd..b565bef4c442391c8315c522a18374e07b495bbd 100644 (file)
@@ -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 (file)
index 0000000..e3b0070
--- /dev/null
@@ -0,0 +1,2 @@
+Restore behavior from 3.10 when tracing an exception raised within a with
+statement.
index 9d3ff74bace6c8eb999c981aa6ebf66a582aa742..9e56b50ee844b4a02fa7c4936c50b3417963b317 100644 (file)
@@ -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: