[Python-checkins] Mark POP_TOP at end of expression statement as artificial, to conform to PEP 626. (GH-24860)

markshannon webhook-mailer at python.org
Mon Mar 15 10:24:38 EDT 2021


https://github.com/python/cpython/commit/c5440937efab6a99d54340c902dfb21e86874bc3
commit: c5440937efab6a99d54340c902dfb21e86874bc3
branch: master
author: Mark Shannon <mark at hotpy.org>
committer: markshannon <mark at hotpy.org>
date: 2021-03-15T14:24:25Z
summary:

Mark POP_TOP at end of expression statement as artificial, to conform to PEP 626. (GH-24860)

files:
M Lib/test/test_compile.py
M Python/compile.c

diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index aa08c97c3ada8..591d5bb00b264 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -786,6 +786,14 @@ def or_false(x):
                 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
diff --git a/Python/compile.c b/Python/compile.c
index 942614fdab850..ea1bf6bf923af 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -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;
 }



More information about the Python-checkins mailing list