ruff
1ccbaebd - [ty] Add bidirectional type context for TypedDict `get()` defaults (#24231)

Commit
17 days ago
[ty] Add bidirectional type context for TypedDict `get()` defaults (#24231) ## Summary Previously, `get` for a non-required field had these overloads: ```python get(key: Literal["resolved"]) -> ResolvedData | None get(key: Literal["resolved"], default: T) -> ResolvedData | T ``` When you call `td.get("resolved", {})`, the second overload matches. But `T` is inferred from `{}` without any context... So this PR adds a third overload: ```python get(key: Literal["resolved"]) -> ResolvedData | None get(key: Literal["resolved"], default: ResolvedData) -> ResolvedData get(key: Literal["resolved"], default: T) -> ResolvedData | T ```
Author
Parents
Loading