mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:55:08 +00:00
red_knot_python_semantic: add invalid assignment diagnostic snapshot
This tests the diagnostic rendering of a case that wasn't previously covered by snapshots: when unpacking fails because there are too few values, but where the left hand side can tolerate "N or more." In the code, this is a distinct diagnostic, so we capture it here. (Sorry about the diff here, but it made sense to rename the other sections and that changes the name of the snapshot file.)
This commit is contained in:
parent
3b300559ab
commit
298f43f34e
4 changed files with 40 additions and 6 deletions
|
@ -8,14 +8,20 @@
|
|||
a, b = 1 # error: [not-iterable]
|
||||
```
|
||||
|
||||
## Too many values to unpack
|
||||
## Exactly too many values to unpack
|
||||
|
||||
```py
|
||||
a, b = (1, 2, 3) # error: [invalid-assignment]
|
||||
```
|
||||
|
||||
## Too few values to unpack
|
||||
## Exactly too few values to unpack
|
||||
|
||||
```py
|
||||
a, b = (1,) # error: [invalid-assignment]
|
||||
```
|
||||
|
||||
## Too few values to unpack
|
||||
|
||||
```py
|
||||
[a, *b, c, d] = (1, 2) # error: [invalid-assignment]
|
||||
```
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
source: crates/red_knot_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: unpacking.md - Unpacking - Exactly too few values to unpack
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unpacking.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | a, b = (1,) # error: [invalid-assignment]
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:invalid-assignment
|
||||
--> /src/mdtest_snippet.py:1:1
|
||||
|
|
||||
1 | a, b = (1,) # error: [invalid-assignment]
|
||||
| ^^^^ Not enough values to unpack (expected 2, got 1)
|
||||
|
|
||||
|
||||
```
|
|
@ -3,7 +3,7 @@ source: crates/red_knot_test/src/lib.rs
|
|||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: unpacking.md - Unpacking - Too many values to unpack
|
||||
mdtest name: unpacking.md - Unpacking - Exactly too many values to unpack
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unpacking.md
|
||||
---
|
||||
|
|
@ -12,7 +12,7 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unpack
|
|||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | a, b = (1,) # error: [invalid-assignment]
|
||||
1 | [a, *b, c, d] = (1, 2)
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
@ -21,8 +21,8 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unpack
|
|||
error: lint:invalid-assignment
|
||||
--> /src/mdtest_snippet.py:1:1
|
||||
|
|
||||
1 | a, b = (1,) # error: [invalid-assignment]
|
||||
| ^^^^ Not enough values to unpack (expected 2, got 1)
|
||||
1 | [a, *b, c, d] = (1, 2)
|
||||
| ^^^^^^^^^^^^^ Not enough values to unpack (expected 3 or more, got 2)
|
||||
|
|
||||
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue