Skip to content

feat: support PEP 798 unpacking comprehensions - #353

Open
StudentWeis wants to merge 1 commit into
tree-sitter:masterfrom
StudentWeis:fix/pep798-unpacking-comprehensions
Open

StudentWeis wants to merge 1 commit into
tree-sitter:masterfrom
StudentWeis:fix/pep798-unpacking-comprehensions

Conversation

@StudentWeis

Copy link
Copy Markdown

Python 3.15 permits unpacking in comprehension bodies, but tuple operands such as [*("prefix", x) for x in xs] and dictionary unpacking such as {**x for x in xs} currently produce ERROR nodes instead of comprehension trees. Allow list_splat bodies in list/set comprehensions and generator expressions, and dictionary_splat bodies in dictionary comprehensions.

Fixes #352.

The handwritten grammar change is four lines, following the focused approach linked in the PEP 798 discussion. It leaves the general list_splat_pattern rule unchanged (unlike the broader changes in #320).

Four corpus cases cover 14 expressions: identifier, tuple and call operands, dictionary unpacking, filters, multiple for clauses, async comprehensions, and a generator used as the sole call argument. The existing Lists expectations are also corrected: [*a.b], [*a[b].c], and [*a()] now place the complete expression inside list_splat, rather than treating the splat as the attribute receiver or callee (related to #314).

Generated files are included, regenerated with CLI 0.25.9 to match the repository. The large parser.c diff is generated parse-table churn; a second generation reproduces all three generated files byte-for-byte.

Validation on Linux x86_64:

  • tree-sitter test: all 121 corpus cases pass; 34 highlighting assertions and 5 tag assertions pass.
  • cargo test --locked: Rust binding test and doctest pass.
  • npm run lint and git diff --check: pass.
  • Compiled cccc's Python adapter against this grammar and Rust tree-sitter 0.27.0 in a temporary harness: all five original repro variants have no parse errors and retain their loop node (cognitive/cyclomatic scores 1/2 instead of 0/1).

Node/Python/Go/Swift binding tests and the external example repositories were not run locally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Python 3.15 PEP 798 unpacking comprehensions produce parse errors

1 participant