]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46331: Do not set line number of instruction storing doc-string. (GH-30518)
authorMark Shannon <mark@hotpy.org>
Tue, 11 Jan 2022 11:28:30 +0000 (11:28 +0000)
committerGitHub <noreply@github.com>
Tue, 11 Jan 2022 11:28:30 +0000 (11:28 +0000)
Lib/test/test_sys_settrace.py
Misc/NEWS.d/next/Core and Builtins/2022-01-10-16-21-54.bpo-46331.h1AC-i.rst [new file with mode: 0644]
Python/compile.c

index 8e430f72f63cc36f5ce0292e4883126ba966dcb7..883b2842f2c77e7a21c0078cb65e82dbcf5636ad 100644 (file)
@@ -1403,6 +1403,25 @@ class TraceTestCase(unittest.TestCase):
              (3, 'line'),
              (3, 'return')])
 
+    def test_class_creation_with_docstrings(self):
+
+        def func():
+            class Class_1:
+                ''' the docstring. 2'''
+                def __init__(self):
+                    ''' Another docstring. 4'''
+                    self.a = 5
+
+        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"""
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-01-10-16-21-54.bpo-46331.h1AC-i.rst b/Misc/NEWS.d/next/Core and Builtins/2022-01-10-16-21-54.bpo-46331.h1AC-i.rst
new file mode 100644 (file)
index 0000000..8bb9a99
--- /dev/null
@@ -0,0 +1,2 @@
+Do not set line number of instruction storing doc-string. Fixes regression
+introduced in 3.11 alpha.
index 590ca9dbfc6a31de3937b6ab525d7c234c2dff7b..0d821d4183f125b96d815f16850e93bcf07bc9f3 100644 (file)
@@ -2034,6 +2034,7 @@ compiler_body(struct compiler *c, asdl_stmt_seq *stmts)
             st = (stmt_ty)asdl_seq_GET(stmts, 0);
             assert(st->kind == Expr_kind);
             VISIT(c, expr, st->v.Expr.value);
+            UNSET_LOC(c);
             if (!compiler_nameop(c, __doc__, Store))
                 return 0;
         }