Skip to content

Support starred subscripts in Python 3.11+ - #248

Closed
hulkbig wants to merge 1 commit into
davidhalter:masterfrom
hulkbig:fix/pep646-starred-subscripts-20261012
Closed

hulkbig wants to merge 1 commit into
davidhalter:masterfrom
hulkbig:fix/pep646-starred-subscripts-20261012

Conversation

@hulkbig

@hulkbig hulkbig commented Oct 12, 2026

Copy link
Copy Markdown

Summary

Related #223.

Support the starred-index syntax introduced by PEP 646, grammar change 1 in the Python 3.11–3.14 grammars. For example, parso.load_grammar(version='3.11').parse('x = tuple[*Ts]\n', error_recovery=False) currently raises ParserSyntaxError for valid Python.

  • Allow single and multiple unpackings, mixed slices, and full expressions after *, including boolean, conditional, and lambda expressions.
  • Normalize the dedicated grammar rule to the existing star_expr CST node and recognize it in the error finder. Existing subscript nodes keep their slice meaning.
  • Preserve rejection in the Python 3.6–3.10 grammars, reject starred slice boundaries, and keep the narrower starred-expression syntax in other contexts.
  • Add strict/recovery parsing, diagnostics, round-trip, CST-shape, and incremental-edit regression tests.

This change covers starred subscripts only. It does not implement starred *args annotations or additional PEP 695 support.

Validation

Tested from base b26da16316da46e4770d589ed5f8d404531a22af on Linux:

  • Full Parso suite: 2,547 passed on CPython 3.8.20; 2,545 passed on 3.12.14; 2,544 passed on 3.13.5. The existing error-case collection is runtime-dependent, accounting for the different totals.
  • All 556 focused new test cases pass. The same tests on the unmodified base produce 199 failures and 357 passes.
  • flake8 --extend-ignore F401 parso test/*.py setup.py scripts/ with flake8 5.0.4, and zuban check with zuban 0.5.1: passed.
  • 1,683 star/slice candidates compared with each of CPython 3.8, 3.12, and 3.13: no syntax-acceptance mismatches. Tree dumps and diagnostics for 41 existing source files match the base across all nine supported grammar versions.

Jedi downstream checks

Jedi 2e3e9057078a328d846aff43d88e00c13d7cccd5, with its exact submodules, was tested on CPython 3.12.14. The complete default suite has identical outcomes with baseline and patched Parso: 4,002 passed, 21 skipped, 5 xfailed, and 2 failed, across 4,030 tests.

Both failures reproduce on the base and stem from this sandbox:

  • test_complete_expanduser assumes HOME contains a visible entry; this HOME does not.
  • test_relative_import discovers the sandbox's /tmp/.git marker and chooses a different project root.

The suite is therefore not all green, but no test outcome regressed. An additional 17 valid cases and 8 malformed/incomplete cases check parsing, diagnostics, round-tripping, and public-API stability. These checks do not establish TypeVarTuple inference semantics. The opt-in third-party corpus and full Python/OS matrix were not run.

AI disclosure: AI tools were used for the implementation, tests, and a separate independent code review. The validation results above come from executed checks.

@hulkbig
hulkbig marked this pull request as ready for review October 12, 2026 09:02
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.

2 participants