Skip to content
Merged
Show file tree
Hide file tree
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
not correct
  • Loading branch information
JelleZijlstra committed Apr 22, 2024
commit 5ade8d4836a23567eddff7251ae385c502f7d981
5 changes: 4 additions & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ static PyCodeObject *optimize_and_assemble(struct compiler *, int addNone);

#define CAPSULE_NAME "compile.c compiler unit"

static inline bool in_class_like_block(struct compiler *c) {
return c->u->u_ste->ste_type == ClassBlock || c->u->u_ste->ste_can_see_class_scope;
}

static int
compiler_setup(struct compiler *c, mod_ty mod, PyObject *filename,
Expand Down Expand Up @@ -5460,7 +5463,7 @@ push_inlined_comprehension_state(struct compiler *c, location loc,
PySTEntryObject *entry,
inlined_comprehension_state *state)
{
int in_class_block = (c->u->u_ste->ste_type == ClassBlock) && !c->u->u_in_inlined_comp;
int in_class_block = in_class_like_block(c) && !c->u->u_in_inlined_comp;
c->u->u_in_inlined_comp++;
// iterate over names bound in the comprehension and ensure we isolate
// them from the outer scope as needed
Expand Down
3 changes: 2 additions & 1 deletion Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,8 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
// free vars in comprehension that are locals in outer scope can
// now simply be locals, unless they are free in comp children,
// or if the outer scope is a class block
if (!is_free_in_any_child(comp, k) && ste->ste_type != ClassBlock) {
if (!is_free_in_any_child(comp, k) && ste->ste_type != ClassBlock
&& !ste->ste_can_see_class_scope) {
if (PySet_Discard(comp_free, k) < 0) {
return 0;
}
Expand Down