mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 14:51:25 +00:00
[ty] More precise type inference for dictionary literals (#20523)
## Summary Extends https://github.com/astral-sh/ruff/pull/20360 to dictionary literals. This also improves our `TypeDict` support by passing through nested type context.
This commit is contained in:
parent
f2cc2f604f
commit
bea92c8229
8 changed files with 265 additions and 120 deletions
|
@ -139,6 +139,15 @@ reveal_type(n) # revealed: list[Literal[1, 2, 3]]
|
|||
# error: [invalid-assignment] "Object of type `list[Unknown | str]` is not assignable to `list[LiteralString]`"
|
||||
o: list[typing.LiteralString] = ["a", "b", "c"]
|
||||
reveal_type(o) # revealed: list[LiteralString]
|
||||
|
||||
p: dict[int, int] = {}
|
||||
reveal_type(p) # revealed: dict[int, int]
|
||||
|
||||
q: dict[int | str, int] = {1: 1, 2: 2, 3: 3}
|
||||
reveal_type(q) # revealed: dict[int | str, int]
|
||||
|
||||
r: dict[int | str, int | str] = {1: 1, 2: 2, 3: 3}
|
||||
reveal_type(r) # revealed: dict[int | str, int | str]
|
||||
```
|
||||
|
||||
## Incorrect collection literal assignments are complained aobut
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue