10000 bpo-44297: Fix missing line number in generator expressions by markshannon · Pull Request #26801 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44297: Fix missing line number in generator expressions #26801

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 3 commits into from
Jun 21, 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
15 changes: 15 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,21 @@ def aug_store_attr():
for (_, _, line) in func.__code__.co_lines() ]
self.assertEqual(lines, code_lines)

def test_line_number_genexp(self):

def return_genexp():
return (1
for
x
in
y)
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
for (_, _, line) in genexp_code.co_lines() ]
self.assertEqual(genexp_lines, code_lines)


def test_big_dict_literal(self):
# The compiler has a flushing point in "compiler_dict" that calls compiles
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Make sure that the line number is set when entering a comprehension scope.
Ensures that backtraces inclusing generator expressions show the correct
line number.
1 change: 1 addition & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4900,6 +4900,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
{
goto error;
}
SET_LOC(c, e);

is_async_generator = c->u->u_ste->ste_coroutine;

Expand Down
Loading
0