]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Mark POP_TOP at end of expression statement as artificial, to conform to PEP 626...
authorMark Shannon <mark@hotpy.org>
Mon, 15 Mar 2021 14:24:25 +0000 (14:24 +0000)
committerGitHub <noreply@github.com>
Mon, 15 Mar 2021 14:24:25 +0000 (14:24 +0000)
Lib/test/test_compile.py
Python/compile.c

index aa08c97c3ada8aec73d4845ad2817d31b3714332..591d5bb00b264eebe63bdff307bd9e9aaf93ed0c 100644 (file)
@@ -786,6 +786,14 @@ if 1:
                 self.assertIn('LOAD_', opcodes[0].opname)
                 self.assertEqual('RETURN_VALUE', opcodes[1].opname)
 
+    def test_lineno_procedure_call(self):
+        def call():
+            (
+                print()
+            )
+        line1 = call.__code__.co_firstlineno + 1
+        assert line1 not in [line for (_, _, line) in call.__code__.co_lines()]
+
     def test_lineno_after_implicit_return(self):
         TRUE = True
         # Don't use constant True or False, as compiler will remove test
index 942614fdab8502d39cdb22783318545c563724d1..ea1bf6bf923afdcdddb4f3c7bb022bbb639fb572 100644 (file)
@@ -3397,6 +3397,8 @@ compiler_visit_stmt_expr(struct compiler *c, expr_ty value)
     }
 
     VISIT(c, expr, value);
+    /* Mark POP_TOP as artificial */
+    c->u->u_lineno = -1;
     ADDOP(c, POP_TOP);
     return 1;
 }