[ty] implement TypedDict structural assignment (#21467)

Closes https://github.com/astral-sh/ty/issues/1387.
This commit is contained in:
Jack O'Connor
2025-11-20 13:15:28 -08:00
committed by GitHub
parent 1b28fc1f14
commit eb7c098d6b
11 changed files with 678 additions and 59 deletions

View File

@@ -482,17 +482,14 @@ class TD2(TypedDict):
x: str
def f(self, dt: dict[str, Any], key: str):
# TODO: This should not error once typed dict assignability is implemented.
# error: [invalid-assignment]
x1: TD = dt.get(key, {})
reveal_type(x1) # revealed: TD
reveal_type(x1) # revealed: Any
x2: TD = dt.get(key, {"x": 0})
reveal_type(x2) # revealed: Any
x3: TD | None = dt.get(key, {})
# TODO: This should reveal `Any` once typed dict assignability is implemented.
reveal_type(x3) # revealed: Any | None
reveal_type(x3) # revealed: Any
x4: TD | None = dt.get(key, {"x": 0})
reveal_type(x4) # revealed: Any