]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44616: Mark all clean up instructions at end of named exception block as artifici...
authorMark Shannon <mark@hotpy.org>
Wed, 14 Jul 2021 09:08:38 +0000 (10:08 +0100)
committerGitHub <noreply@github.com>
Wed, 14 Jul 2021 09:08:38 +0000 (10:08 +0100)
Lib/test/test_sys_settrace.py
Python/compile.c
Python/importlib_zipimport.h

index c42c69d0c807b58c4567504166cff8a9b55cd7f6..ce247739b0dc1d05895655e838cd3b1305d864d4 100644 (file)
@@ -1077,6 +1077,29 @@ class TraceTestCase(unittest.TestCase):
              (1, 'line'),
              (1, 'return')])
 
+    def test_no_tracing_of_named_except_cleanup(self):
+
+        def func():
+            x = 0
+            try:
+                1/x
+            except ZeroDivisionError as error:
+                if x:
+                    raise
+            return "done"
+
+        self.run_and_compare(func,
+        [(0, 'call'),
+            (1, 'line'),
+            (2, 'line'),
+            (3, 'line'),
+            (3, 'exception'),
+            (4, 'line'),
+            (5, 'line'),
+            (7, 'line'),
+            (7, 'return')])
+
+
 class SkipLineEventsTraceTestCase(TraceTestCase):
     """Repeat the trace tests, but with per-line events skipped"""
 
index bb5c2eca960de44cc1e58f31df9d919665d7d57c..81648c5111f9aacaf0194c77e6b751949b2634b7 100644 (file)
@@ -3312,11 +3312,11 @@ compiler_try_except(struct compiler *c, stmt_ty s)
             /* second # body */
             VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
             compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body);
+            /* name = None; del name; # Mark as artificial */
+            UNSET_LOC(c);
             ADDOP(c, POP_BLOCK);
             ADDOP(c, POP_BLOCK);
             ADDOP(c, POP_EXCEPT);
-            /* name = None; del name; # Mark as artificial */
-            UNSET_LOC(c);
             ADDOP_LOAD_CONST(c, Py_None);
             compiler_nameop(c, handler->v.ExceptHandler.name, Store);
             compiler_nameop(c, handler->v.ExceptHandler.name, Del);
@@ -3348,7 +3348,6 @@ compiler_try_except(struct compiler *c, stmt_ty s)
                 return 0;
             VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
             compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body);
-            /* name = None; del name; # Mark as artificial */
             UNSET_LOC(c);
             ADDOP(c, POP_BLOCK);
             ADDOP(c, POP_EXCEPT);
index d4ba6ee7bdd81aaeb3919e8c0d45f60bcc34747e..15ad71f72b19d0a067dd2858ba7aba949d0a1451 100644 (file)
@@ -1403,8 +1403,8 @@ const unsigned char _Py_M__zipimport[] = {
     23,35,13,20,20,29,30,34,30,42,44,53,20,54,13,17,
     20,24,13,17,16,26,13,54,17,39,28,43,44,48,50,57,
     59,67,69,77,79,83,28,84,21,25,21,25,0,0,17,39,
-    24,35,17,39,17,39,17,39,17,39,36,39,21,33,21,39,
-    21,39,21,39,21,39,21,39,0,0,0,0,0,0,0,0,
+    24,35,17,39,17,39,17,39,17,39,36,39,21,33,21,33,
+    21,33,21,33,21,33,21,33,0,0,0,0,0,0,0,0,
     0,0,24,39,40,47,49,53,24,54,17,21,16,20,24,28,
     16,28,13,25,17,25,23,32,33,34,23,35,13,20,20,24,
     26,35,37,44,20,44,13,44,13,44,13,44,12,24,9,83,