diff --git a/mypy/types.py b/mypy/types.py index 5a05962dc480..9781861edec1 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -163,6 +163,7 @@ "builtins.tuple", "typing.Iterable", "typing.Container", + "typing.Collection", "typing.Sequence", "typing.Reversible", ) diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index 17a1fea22ef0..25f7ea106543 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -4601,6 +4601,23 @@ inputs: Sequence[Component] = [{ [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] +[case testTypedDictTupleExpressionWithCollectionContext] +import collections.abc +from typing import Collection, TypedDict + +class Item(TypedDict): + x: int + +def take(items: Collection[Item]) -> None: ... +def take_abc(items: collections.abc.Collection[Item]) -> None: ... + +take(({"x": 1}, {"x": 2})) +take_abc(({"x": 1}, {"x": 2})) +items: Collection[Item] = ({"x": 1}, {"x": 2}) +abc_items: collections.abc.Collection[Item] = ({"x": 1}, {"x": 2}) +[builtins fixtures/dict.pyi] +[typing fixtures/typing-typeddict.pyi] + [case testTypedDictAssignableToWiderContext] from typing import TypedDict, Union diff --git a/test-data/unit/fixtures/typing-typeddict.pyi b/test-data/unit/fixtures/typing-typeddict.pyi index 0bc5637b3270..0f1439d21c5b 100644 --- a/test-data/unit/fixtures/typing-typeddict.pyi +++ b/test-data/unit/fixtures/typing-typeddict.pyi @@ -47,6 +47,8 @@ class Iterable(Protocol[T_co]): class Iterator(Iterable[T_co], Protocol): def __next__(self) -> T_co: pass +class Collection(Iterable[T_co]): pass + class Sequence(Iterable[T_co]): def __getitem__(self, n: Any) -> T_co: pass # type: ignore[explicit-any]