gh-140253: Improve the syntax error from an ill-positioned double-star subpattern (#140254)

This commit is contained in:
Bartosz Sławecki 2025-10-22 20:29:14 +02:00 committed by GitHub
parent 76fea5596c
commit b3b0d75069
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 922 additions and 765 deletions

View file

@ -370,12 +370,6 @@
Traceback (most recent call last):
SyntaxError: invalid syntax
>>> match ...:
... case {**rest, "key": value}:
... ...
Traceback (most recent call last):
SyntaxError: invalid syntax
>>> match ...:
... case {**_}:
... ...
@ -2240,7 +2234,7 @@
Traceback (most recent call last):
SyntaxError: invalid character '£' (U+00A3)
Invalid pattern matching constructs:
Invalid pattern matching constructs:
>>> match ...:
... case 42 as _:
@ -2302,6 +2296,24 @@
Traceback (most recent call last):
SyntaxError: positional patterns follow keyword patterns
>>> match ...:
... case {**double_star, "spam": "eggs"}:
... ...
Traceback (most recent call last):
SyntaxError: double star pattern must be the last (right-most) subpattern in the mapping pattern
>>> match ...:
... case {"foo": 1, **double_star, "spam": "eggs"}:
... ...
Traceback (most recent call last):
SyntaxError: double star pattern must be the last (right-most) subpattern in the mapping pattern
>>> match ...:
... case {"spam": "eggs", "b": {**d, "ham": "bacon"}}:
... ...
Traceback (most recent call last):
SyntaxError: double star pattern must be the last (right-most) subpattern in the mapping pattern
Uses of the star operator which should fail:
A[:*b]