mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-140253: Improve the syntax error from an ill-positioned double-star subpattern (#140254)
This commit is contained in:
parent
76fea5596c
commit
b3b0d75069
5 changed files with 922 additions and 765 deletions
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue