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:
Andrew Gallant 2025-04-16 09:27:25 -04:00 committed by Andrew Gallant
parent 3b300559ab
commit 298f43f34e
4 changed files with 40 additions and 6 deletions

View file

@ -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]
```

View file

@ -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)
|
```

View file

@ -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
---

View file

@ -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)
|
```