|
1502 | 1502 | Traceback (most recent call last): |
1503 | 1503 | SyntaxError: invalid syntax |
1504 | 1504 |
|
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). |
1506 | 1508 |
|
1507 | 1509 | >>> match 1: |
1508 | 1510 | ... case x | 1: pass |
|
1517 | 1519 | >>> match 1: |
1518 | 1520 | ... case 1 | x: pass |
1519 | 1521 | 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) |
1521 | 1538 |
|
1522 | 1539 | >>> match 1: |
1523 | 1540 | ... case ("user", {"id": id}) | ("admin", {"name": name}): pass |
1524 | 1541 | 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']) |
1526 | 1543 |
|
1527 | 1544 | >>> match 1: |
1528 | 1545 | ... case ("user", {"id": id}) | ("admin", {"id": id}) | ("other", {"ip": ip}): pass |
1529 | 1546 | 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']) |
1531 | 1548 |
|
1532 | 1549 | Incomplete dictionary literals |
1533 | 1550 |
|
|
0 commit comments