8000 [3.14] GH-135171: Fix generator expressions one last time (hopefully) by markshannon · Pull Request #135225 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.14] GH-135171: Fix generator expressions one last time (hopefully) #135225

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 6 commits into from
Jun 9, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move GET_ITER back to genexpr creation
  • Loading branch information
markshannon committed Jun 6, 2025
commit 225e36abcd87214c8114ce3d348363612514ffd7
11 changes: 8 additions & 3 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -4411,7 +4411,7 @@ codegen_sync_comprehension_generator(compiler *c, location loc,

comprehension_ty gen = (comprehension_ty)asdl_seq_GET(generators,
gen_index);

int is_outer_genexpr = gen_index == 0 && type == COMP_GENEXP;
if (!iter_on_stack) {
if (gen_index == 0) {
assert(METADATA(c)->u_argcount == 1);
Expand Down Expand Up @@ -4442,14 +4442,15 @@ codegen_sync_comprehension_generator(compiler *c, location loc,
}
if (IS_JUMP_TARGET_LABEL(start)) {
VISIT(c, expr, gen->iter);
ADDOP(c, LOC(gen->iter), GET_ITER);
}
}
}

if (IS_JUMP_TARGET_LABEL(start)) {
depth++;
ADDOP(c, LOC(gen->iter), GET_ITER);
if (!is_outer_genexpr) {
ADDOP(c, LOC(gen->iter), GET_ITER);
}
USE_LABEL(c, start);
ADDOP_JUMP(c, LOC(gen->iter), FOR_ITER, anchor);
}
Expand Down Expand Up @@ -4775,6 +4776,7 @@ codegen_comprehension(compiler *c, expr_ty e, int type,
location loc = LOC(e);

outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
int is_sync_genexpr = type == COMP_GENEXP && !outermost->is_async;
if (is_inlined) {
VISIT(c, expr, outermost->iter);
if (push_inlined_comprehension_state(c, loc, entry, &inline_state)) {
Expand Down Expand Up @@ -4851,6 +4853,9 @@ codegen_comprehension(compiler *c, expr_ty e, int type,
Py_CLEAR(co);

VISIT(c, expr, outermost->iter);
if (is_sync_genexpr) {
ADDOP(c, loc, GET_ITER);
}
ADDOP_I(c, loc, CALL, 0);

if (is_async_comprehension && type != COMP_GENEXP) {
Expand Down
0