Skip to content

Commit

Permalink
Mark POP_TOP at end of expression statement as artificial, to conform…
Browse files Browse the repository at this point in the history
… to PEP 626. (GH-24860)
  • Loading branch information
markshannon authored Mar 15, 2021
1 parent 35d5068 commit c544093
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c544093

Please sign in to comment.