8000 Mark POP_TOP at end of expression statement as artificial, to conform… · python/cpython@c544093 · GitHub
[go: up one dir, main page]

Skip to content

Commit c544093

Browse files
authored
Mark POP_TOP at end of expression statement as artificial, to conform to PEP 626. (GH-24860)
1 parent 35d5068 commit c544093

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Lib/test/test_compile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,14 @@ def or_false(x):
786786
self.assertIn('LOAD_', opcodes[0].opname)
787787
self.assertEqual('RETURN_VALUE', opcodes[1].opname)
788788

789+
def test_lineno_procedure_call(self):
790+
def call():
791+
(
792+
print()
793+
)
794+
line1 = call.__code__.co_firstlineno + 1
795+
assert line1 not in [line for (_, _, line) in call.__code__.co_lines()]
796+
789797
def test_lineno_after_implicit_return(self):
790798
TRUE = True
791799
# Don't use constant True or False, as compiler will remove test

Python/compile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,6 +3397,8 @@ compiler_visit_stmt_expr(struct compiler *c, expr_ty value)
33973397
}
33983398

33993399
VISIT(c, expr, value);
3400+
/* Mark POP_TOP as artificial */
3401+
c->u->u_lineno = -1;
34003402
ADDOP(c, POP_TOP);
34013403
return 1;
34023404
}

0 commit comments

Comments
 (0)
0