-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[red-knot] Do not panic if named expressions show up in assignment po…
…sition (#13711) Co-authored-by: Carl Meyer <[email protected]>
- Loading branch information
Showing
2 changed files
with
78 additions
and
28 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
crates/red_knot_python_semantic/resources/mdtest/subscript/lists.md
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,33 @@ | ||
# List subscripts | ||
|
||
## Indexing into lists | ||
|
||
A list can be indexed into with: | ||
|
||
- numbers | ||
- slices | ||
|
||
```py | ||
x = [1, 2, 3] | ||
reveal_type(x) # revealed: list | ||
# TODO reveal int | ||
reveal_type(x[0]) # revealed: @Todo | ||
# TODO reveal list | ||
reveal_type(x[0:1]) # revealed: @Todo | ||
# TODO error | ||
reveal_type(x["a"]) # revealed: @Todo | ||
``` | ||
|
||
## Assignments within list assignment | ||
|
||
In assignment, we might also have a named assignment. | ||
This should also get type checked. | ||
|
||
```py | ||
x = [1, 2, 3] | ||
x[0 if (y := 2) else 1] = 5 | ||
# TODO error? (indeterminite index type) | ||
x["a" if (y := 2) else 1] = 6 | ||
# TODO error (can't index via string) | ||
x["a" if (y := 2) else "b"] = 6 | ||
``` |
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