Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"builtins.tuple",
"typing.Iterable",
"typing.Container",
"typing.Collection",
"typing.Sequence",
"typing.Reversible",
)
Expand Down
17 changes: 17 additions & 0 deletions test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test-data/unit/fixtures/typing-typeddict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
Loading