[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:
David Peter 2025-08-06 09:36:33 +02:00 committed by GitHub
parent e917d309f1
commit 4887bdf205
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 489 additions and 158 deletions

View file

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