Fix sub_table ordering for nested inlined comprehensions (PEP 709) by LegNeato · Pull Request #7480 · RustPython/RustPython
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.
Bot
reviewed
LegNeato
deleted the
fix/nested-comprehension-underscore
branch
Copilot AI pushed a commit that referenced this pull request
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters