gh-104374: Remove access to class scopes for inlined comprehensions (#104528)

Co-authored-by: Carl Meyer <carl@oddbird.net>
This commit is contained in:
Jelle Zijlstra 2023-05-17 22:22:17 -07:00 committed by GitHub
parent 152227b569
commit 662aede68b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 125 additions and 9 deletions

View file

@ -674,8 +674,9 @@ 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
if (!is_free_in_any_child(comp, k)) {
// 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 (PySet_Discard(comp_free, k) < 0) {
return 0;
}