mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:49:50 +00:00
[syntax-errors] Detect duplicate keys in match
mapping patterns (#17129)
Summary -- Detects duplicate literals in `match` mapping keys. This PR also adds a `source` method to `SemanticSyntaxContext` to display the duplicated key in the error message by slicing out its range. Test Plan -- New inline tests.
This commit is contained in:
parent
ca0cce3f9c
commit
6e2b8f9696
7 changed files with 1298 additions and 6 deletions
|
@ -0,0 +1,19 @@
|
|||
match x:
|
||||
case {"x": 1, "x": 2}: ...
|
||||
case {b"x": 1, b"x": 2}: ...
|
||||
case {0: 1, 0: 2}: ...
|
||||
case {1.0: 1, 1.0: 2}: ...
|
||||
case {1.0 + 2j: 1, 1.0 + 2j: 2}: ...
|
||||
case {True: 1, True: 2}: ...
|
||||
case {None: 1, None: 2}: ...
|
||||
case {
|
||||
"""x
|
||||
y
|
||||
z
|
||||
""": 1,
|
||||
"""x
|
||||
y
|
||||
z
|
||||
""": 2}: ...
|
||||
case {"x": 1, "x": 2, "x": 3}: ...
|
||||
case {0: 1, "x": 1, 0: 2, "x": 2}: ...
|
|
@ -0,0 +1,2 @@
|
|||
match x:
|
||||
case {x.a: 1, x.a: 2}: ...
|
Loading…
Add table
Add a link
Reference in a new issue