Commit ce916dc
authored
* Fix class-scope inline comprehensions when nested scopes reference `__class__` and friends
In `inline_comprehension()`, when `__class__` / `__classdict__` /
`__conditional_annotations__` appears as `FREE` in a comprehension's
symbol table because a nested scope captured it (e.g. nested lambdas),
this name is still discarded from `comp_free` unconditionally.
This prevents `drop_class_free()` from seeing it, so the appropriate
`ste_needs_(...)` flag is never set on the enclosing class.
That leads to `codegen_make_closure()` throwing `SystemError` when it
couldn't find `__class__` / `__classdict__` /
`__conditional_annotations__` in the class's cellvars.
From now on we just discard from `comp_free` when no child scope
(e.g. a lambda) still needs the name as `FREE`. When a child scope does
need it, keep it in `comp_free` so `drop_class_free()` can set the
appropriate flag and the class creates the implicit cell.
* Fix tests
* Fix typo
* Fix formatting
* Add test checking validity of `__class__` returned
* Prefer 'used' to 'deferred'
1 parent 5804991 commit ce916dc
3 files changed
Lines changed: 43 additions & 4 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
174 | 185 | | |
175 | 186 | | |
176 | 187 | | |
| |||
180 | 191 | | |
181 | 192 | | |
182 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
183 | 203 | | |
184 | 204 | | |
185 | 205 | | |
186 | 206 | | |
187 | 207 | | |
188 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
189 | 214 | | |
190 | 215 | | |
191 | 216 | | |
192 | 217 | | |
193 | 218 | | |
194 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
195 | 226 | | |
196 | 227 | | |
197 | 228 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
834 | 834 | | |
835 | 835 | | |
836 | 836 | | |
837 | | - | |
838 | | - | |
| 837 | + | |
| 838 | + | |
839 | 839 | | |
840 | 840 | | |
841 | 841 | | |
842 | 842 | | |
843 | 843 | | |
844 | | - | |
| 844 | + | |
| 845 | + | |
845 | 846 | | |
846 | 847 | | |
847 | | - | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
848 | 853 | | |
849 | 854 | | |
850 | 855 | | |
| |||
0 commit comments