[ty] dict is not assignable to TypedDict (#21238)

## Summary

A lot of the bidirectional inference work relies on `dict` not being
assignable to `TypedDict`, so I think it makes sense to add this before
fully implementing https://github.com/astral-sh/ty/issues/1387.
This commit is contained in:
Ibraheem Ahmed 2025-11-03 16:57:49 -05:00 committed by GitHub
parent 42adfd40ea
commit 3c8fb68765
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 169 additions and 75 deletions

View file

@ -1685,8 +1685,7 @@ def int_or_str() -> int | str:
x = f([{"x": 1}], int_or_str())
reveal_type(x) # revealed: int | str
# TODO: error: [no-matching-overload] "No overload of function `f` matches arguments"
# we currently incorrectly consider `list[dict[str, int]]` a subtype of `list[T]`
# error: [no-matching-overload] "No overload of function `f` matches arguments"
f([{"y": 1}], int_or_str())
```

View file

@ -277,7 +277,6 @@ def _(flag: bool):
x = f({"x": 1})
reveal_type(x) # revealed: int
# TODO: error: [invalid-argument-type] "Argument to function `f` is incorrect: Expected `T`, found `dict[str, int]`"
# we currently consider `TypedDict` instances to be subtypes of `dict`
# error: [invalid-argument-type] "Argument to function `f` is incorrect: Expected `T`, found `dict[Unknown | str, Unknown | int]`"
f({"y": 1})
```