8000 gh-109118: Make comprehensions work within annotation scopes, but without inlining by JelleZijlstra · Pull Request #118160 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-109118: Make comprehensions work within annotation scopes, but without inlining #118160

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 7 commits into from
Apr 28, 2024
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
Revert "not correct"
This reverts commit 5ade8d4.
  • Loading branch information
JelleZijlstra committed Apr 26, 2024
commit ba90c9764ba62b288ef0b262ff3b57ecb9e16161
5 changes: 1 addition & 4 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,6 @@ 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 @@ -5463,7 +5460,7 @@ push_inlined_comprehension_state(struct compiler *c, location loc,
PySTEntryObject *entry,
inlined_comprehension_state *state)
{
int in_class_block = in_class_like_block(c) && !c->u->u_in_inlined_comp;
int in_class_block = (c->u->u_ste->ste_type == ClassBlock) && !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: 1 addition & 2 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,7 @@ 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
&& !ste->ste_can_see_class_scope) {
if (!is_free_in_any_child(comp, k) && ste->ste_type != ClassBlock) {
if (PySet_Discard(comp_free, k) < 0) {
return 0;
}
Expand Down
0