Skip to content
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

bpo-44622: Set line number of END_ASYNC_FOR to match that of iterator. #27160

Merged
merged 4 commits into from
Jul 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
12 changes: 11 additions & 1 deletion Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,20 @@ def return_genexp():
genexp_lines = [None, 1, 3, 1]

genexp_code = return_genexp.__code__.co_consts[1]
code_lines = [None if line is None else line-return_genexp.__code__.co_firstlineno
code_lines = [ None if line is None else line-return_genexp.__code__.co_firstlineno
for (_, _, line) in genexp_code.co_lines() ]
self.assertEqual(genexp_lines, code_lines)

def test_line_number_implicit_return_after_async_for(self):

async def test(aseq):
async for i in aseq:
body

expected_lines = [None, 1, 2, 1]
code_lines = [ None if line is None else line-test.__code__.co_firstlineno
for (_, _, line) in test.__code__.co_lines() ]
self.assertEqual(expected_lines, code_lines)

def test_big_dict_literal(self):
# The compiler has a flushing point in "compiler_dict" that calls compiles
Expand Down
4 changes: 3 additions & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3002,7 +3002,9 @@ compiler_async_for(struct compiler *c, stmt_ty s)
/* Except block for __anext__ */
compiler_use_next_block(c, except);

UNSET_LOC(c);
/* Use same line number as the iterator,
* as the END_ASYNC_FOR succeeds the `for`, not the body. */
SET_LOC(c, s->v.AsyncFor.iter);
ADDOP(c, END_ASYNC_FOR);

/* `else` block */
Expand Down