-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error recovery for match patterns
- Loading branch information
1 parent
1cf7954
commit e1f1cc8
Showing
11 changed files
with
3,042 additions
and
764 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
crates/ruff_python_parser/resources/invalid/statements/match/invalid_class_pattern.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Invalid keyword pattern in class argument | ||
match subject: | ||
case Foo(x as y = 1): | ||
pass | ||
case Foo(x | y = 1): | ||
pass | ||
case Foo([x, y] = 1): | ||
pass | ||
case Foo({False: 0} = 1): | ||
pass | ||
case Foo(1=1): | ||
pass | ||
case Foo(Bar()=1): | ||
pass | ||
# Positional pattern cannot follow keyword pattern | ||
# case Foo(x, y=1, z): | ||
# pass |
35 changes: 35 additions & 0 deletions
35
crates/ruff_python_parser/resources/invalid/statements/match/invalid_lhs_or_rhs_pattern.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
match invalid_lhs_pattern: | ||
case Foo() + 1j: | ||
pass | ||
case x + 2j: | ||
pass | ||
case _ + 3j: | ||
pass | ||
case (1 | 2) + 4j: | ||
pass | ||
case [1, 2] + 5j: | ||
pass | ||
case {True: 1} + 6j: | ||
pass | ||
case 1j + 2j: | ||
pass | ||
|
||
match invalid_rhs_pattern: | ||
case 1 + Foo(): | ||
pass | ||
case 2 + x: | ||
pass | ||
case 3 + _: | ||
pass | ||
case 4 + (1 | 2): | ||
pass | ||
case 5 + [1, 2]: | ||
pass | ||
case 6 + {True: 1}: | ||
pass | ||
case 1 + 2: | ||
pass | ||
|
||
match invalid_lhs_rhs_pattern: | ||
case Foo() + Bar(): | ||
pass |
17 changes: 17 additions & 0 deletions
17
crates/ruff_python_parser/resources/invalid/statements/match/invalid_mapping_pattern.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Starred expression is not allowed as a mapping pattern key | ||
match subject: | ||
case {*key}: | ||
pass | ||
case {*key: 1}: | ||
pass | ||
case {*key 1}: | ||
pass | ||
case {*key, None: 1}: | ||
pass | ||
|
||
# Double starred pattern cannot follow any other pattern | ||
match subject: | ||
case {**rest, None: 1}: | ||
pass | ||
case {**rest1, **rest2, None: 1}: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.