mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00:00
[ty] Infer types for key-based access on TypedDicts (#19763)
## Summary This PR adds type inference for key-based access on `TypedDict`s and a new diagnostic for invalid subscript accesses: ```py class Person(TypedDict): name: str age: int | None alice = Person(name="Alice", age=25) reveal_type(alice["name"]) # revealed: str reveal_type(alice["age"]) # revealed: int | None alice["naem"] # Unknown key "naem" - did you mean "name"? ``` ## Test Plan Updated Markdown tests
This commit is contained in:
parent
e917d309f1
commit
4887bdf205
13 changed files with 489 additions and 158 deletions
|
@ -46,6 +46,7 @@ mod util;
|
|||
#[cfg(feature = "testing")]
|
||||
pub mod pull_types;
|
||||
|
||||
type FxOrderMap<K, V> = ordermap::map::OrderMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||
type FxOrderSet<V> = ordermap::set::OrderSet<V, BuildHasherDefault<FxHasher>>;
|
||||
type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||
type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue