forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[red-knot] Handle invalid assignment targets (astral-sh#14325)
## Summary This fixes several panics related to invalid assignment targets. All of these led to some a crash, previously: ```py (x.y := 1) # only name-expressions are valid targets of named expressions ([x, y] := [1, 2]) # same (x, y): tuple[int, int] = (2, 3) # tuples are not valid targets for annotated assignments (x, y) += 2 # tuples are not valid targets for augmented assignments ``` closes astral-sh#14321 closes astral-sh#14322 ## Test Plan I symlinked four files from `crates/ruff_python_parser/resources` into the red knot corpus, as they seemed like ideal test files for this exact scenario. I think eventually, it might be a good idea to simply include *all* invalid-syntax examples from the parser tests into red knots corpus (I believe we're actually not too far from that goal). Or expand the scope of the corpus test to this directory. Then we can get rid of these symlinks again.
- Loading branch information
Showing
6 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
crates/red_knot_workspace/resources/test/corpus/04_assign_invalid_target.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 @@ | ||
../../../../ruff_python_parser/resources/invalid/statements/invalid_assignment_targets.py |
1 change: 1 addition & 0 deletions
1
crates/red_knot_workspace/resources/test/corpus/04_assign_named_expr_invalid_target.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 @@ | ||
../../../../ruff_python_parser/resources/invalid/expressions/named/invalid_target.py |
1 change: 1 addition & 0 deletions
1
crates/red_knot_workspace/resources/test/corpus/04_aug_assign_invalid_target.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 @@ | ||
../../../../ruff_python_parser/resources/invalid/statements/invalid_augmented_assignment_target.py |
1 change: 1 addition & 0 deletions
1
crates/red_knot_workspace/resources/test/corpus/98_ann_assign_invalid_target.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 @@ | ||
../../../../ruff_python_parser/resources/inline/err/ann_assign_stmt_invalid_target.py |