Commit 2180f53
authored
Fix sub_table ordering for nested inlined comprehensions (PEP 709) (#7480)
When an inlined comprehension's first iterator expression contains
nested scopes (such as a lambda), those scopes' sub_tables appear at the
current position in the parent's sub_table list. The previous code
spliced the comprehension's own child sub_tables (e.g. inner inlined
comprehensions) into that same position before compiling the iterator,
which shifted the iterator's sub_tables to wrong indices.
Move the splice after the first iterator is compiled so its sub_tables
are consumed at their original positions.
Fixes nested list comprehensions like:
```python
[[x for _, x in g] for _, g in itertools.groupby(..., lambda x: ...)]
```
Disclosure: I used AI to develop the patch though I was heavily
involved.1 parent 3c62b56 commit 2180f53
File tree
2 files changed
+47
-5
lines changed- crates/codegen/src
- extra_tests/snippets
2 files changed
+47
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8013 | 8013 | | |
8014 | 8014 | | |
8015 | 8015 | | |
8016 | | - | |
8017 | | - | |
8018 | 8016 | | |
8019 | 8017 | | |
8020 | 8018 | | |
8021 | 8019 | | |
8022 | 8020 | | |
8023 | 8021 | | |
| 8022 | + | |
| 8023 | + | |
| 8024 | + | |
| 8025 | + | |
| 8026 | + | |
| 8027 | + | |
| 8028 | + | |
| 8029 | + | |
| 8030 | + | |
8024 | 8031 | | |
| 8032 | + | |
| 8033 | + | |
| 8034 | + | |
| 8035 | + | |
8025 | 8036 | | |
8026 | 8037 | | |
8027 | 8038 | | |
8028 | 8039 | | |
8029 | 8040 | | |
8030 | | - | |
8031 | | - | |
8032 | | - | |
8033 | 8041 | | |
8034 | 8042 | | |
8035 | 8043 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
0 commit comments