Python: Allow list_splats as type annotations

That is, the `*T` in `def foo(*args : *T): ...`.

This is apparently a piece of syntax we did not support correctly until
now.

In terms of the grammar, we simply add `list_splat` as a possible
alternative for `type` (which could previously only be an `expression`).
We also update `python.tsg` to not specify `expression` those places (as
the relevant stanzas will then not work for `list_splat`s).

This syntax is not supported by the old parser, hence we only add a new
parser test for it.
This commit is contained in:
Taus
2024-10-22 15:17:12 +00:00
parent fcec8e0256
commit 8053e0ed44
4 changed files with 49 additions and 6 deletions

View File

@@ -963,7 +963,7 @@ module.exports = grammar({
field('type', $.type)
)),
type: $ => $.expression,
type: $ => choice($.list_splat, $.expression),
keyword_argument: $ => seq(
field('name', choice($.identifier, $.keyword_identifier)),