Skip to content

bpo-42246: Mark POP_TOP at end of expression statement as artificial, to conform to PEP 626. #24860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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