Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ade8d4

Browse files
committed
not correct
1 parent ad56c5f commit 5ade8d4

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

Python/compile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ static PyCodeObject *optimize_and_assemble(struct compiler *, int addNone);
371371

372372
#define CAPSULE_NAME "compile.c compiler unit"
373373

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

375378
static int
376379
compiler_setup(struct compiler *c, mod_ty mod, PyObject *filename,
@@ -5460,7 +5463,7 @@ push_inlined_comprehension_state(struct compiler *c, location loc,
54605463
PySTEntryObject *entry,
54615464
inlined_comprehension_state *state)
54625465
{
5463-
int in_class_block = (c->u->u_ste->ste_type == ClassBlock) && !c->u->u_in_inlined_comp;
5466+
int in_class_block = in_class_like_block(c) && !c->u->u_in_inlined_comp;
54645467
c->u->u_in_inlined_comp++;
54655468
// iterate over names bound in the comprehension and ensure we isolate
54665469
// them from the outer scope as needed

Python/symtable.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,8 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
810810
// free vars in comprehension that are locals in outer scope can
811811
// now simply be locals, unless they are free in comp children,
812812
// or if the outer scope is a class block
813-
if (!is_free_in_any_child(comp, k) && ste->ste_type != ClassBlock) {
813+
if (!is_free_in_any_child(comp, k) && ste->ste_type != ClassBlock
814+
&& !ste->ste_can_see_class_scope) {
814815
if (PySet_Discard(comp_free, k) < 0) {
815816
return 0;
816817
}

0 commit comments

Comments
 (0)