]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Mark instructions at end of class scope as artificial. (GH-24222)
authorMark Shannon <mark@hotpy.org>
Fri, 15 Jan 2021 13:52:00 +0000 (13:52 +0000)
committerGitHub <noreply@github.com>
Fri, 15 Jan 2021 13:52:00 +0000 (13:52 +0000)
Lib/test/test_sys_settrace.py
Python/compile.c

index 42989862502ac053025a723aee6222464b3dc241..49e89289956862b385680d2bcc4e66af6f81d0de 100644 (file)
@@ -956,6 +956,24 @@ class TraceTestCase(unittest.TestCase):
              (2, 'line'),
              (2, 'return')])
 
+    def test_implicit_return_in_class(self):
+
+        def func():
+            class A:
+                if 3 < 9:
+                    a = 1
+                else:
+                    a = 2
+
+        self.run_and_compare(func,
+            [(0, 'call'),
+             (1, 'line'),
+             (1, 'call'),
+             (1, 'line'),
+             (2, 'line'),
+             (3, 'line'),
+             (3, 'return'),
+             (1, 'return')])
 
 class SkipLineEventsTraceTestCase(TraceTestCase):
     """Repeat the trace tests, but with per-line events skipped"""
index d373d8a4061a3cbe83d3edaf1507fa67786a1746..6aa74cc2d67e42c32e4654ffd456e894a31fe353 100644 (file)
@@ -2371,6 +2371,8 @@ compiler_class(struct compiler *c, stmt_ty s)
             compiler_exit_scope(c);
             return 0;
         }
+        /* The following code is artificial */
+        c->u->u_lineno = -1;
         /* Return __classcell__ if it is referenced, otherwise return None */
         if (c->u->u_ste->ste_needs_class_closure) {
             /* Store __classcell__ into class namespace & return it */