Skip to content

Commit 78a9834

Browse files
committed
increase test coverage
1 parent a31a862 commit 78a9834

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

Lib/test/test_syntax.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,9 @@
15021502
Traceback (most recent call last):
15031503
SyntaxError: invalid syntax
15041504
1505-
Ensure that alternative patterns bind the same names
1505+
Ensure that alternative patterns bind the same names (when there is
1506+
a single capture in the first pattern that is not uniformly captured,
1507+
the error message is sightly different).
15061508
15071509
>>> match 1:
15081510
... case x | 1: pass
@@ -1517,17 +1519,32 @@
15171519
>>> match 1:
15181520
... case 1 | x: pass
15191521
Traceback (most recent call last):
1520-
SyntaxError: alternative patterns bind different names (first pattern binds no names, pattern 2 binds ['x'])
1522+
SyntaxError: alternative patterns bind different names (pattern 1 binds nothing, pattern 2 binds ['x'])
1523+
1524+
>>> match 1:
1525+
... case (x, y) | 1: pass
1526+
Traceback (most recent call last):
1527+
SyntaxError: alternative patterns bind different names (pattern 1 binds ['x', 'y'], pattern 2 binds nothing)
1528+
1529+
>>> match 1:
1530+
... case 1 | ("point", {"x": x, "y": y}): pass
1531+
Traceback (most recent call last):
1532+
SyntaxError: alternative patterns bind different names (pattern 1 binds nothing, pattern 2 binds ['x', 'y'])
1533+
1534+
>>> match 1:
1535+
... case ("point", {"x": x, "y": y}) | 1: pass
1536+
Traceback (most recent call last):
1537+
SyntaxError: alternative patterns bind different names (pattern 1 binds ['x', 'y'], pattern 2 binds nothing)
15211538
15221539
>>> match 1:
15231540
... case ("user", {"id": id}) | ("admin", {"name": name}): pass
15241541
Traceback (most recent call last):
1525-
SyntaxError: alternative patterns bind different names (first pattern binds ['id'], pattern 2 binds ['name'])
1542+
SyntaxError: alternative patterns bind different names (pattern 1 binds ['id'], pattern 2 binds ['name'])
15261543
15271544
>>> match 1:
15281545
... case ("user", {"id": id}) | ("admin", {"id": id}) | ("other", {"ip": ip}): pass
15291546
Traceback (most recent call last):
1530-
SyntaxError: alternative patterns bind different names (first pattern binds ['id'], pattern 3 binds ['ip'])
1547+
SyntaxError: alternative patterns bind different names (pattern 1 binds ['id'], pattern 3 binds ['ip'])
15311548
15321549
Incomplete dictionary literals
15331550

0 commit comments

Comments
 (0)