Skip to content

Commit a732013

Browse files
committed
Fix TypedDict tuple context for Collection
1 parent 37ee432 commit a732013

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

mypy/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"builtins.tuple",
164164
"typing.Iterable",
165165
"typing.Container",
166+
"typing.Collection",
166167
"typing.Sequence",
167168
"typing.Reversible",
168169
)

test-data/unit/check-typeddict.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4601,6 +4601,23 @@ inputs: Sequence[Component] = [{
46014601
[builtins fixtures/dict.pyi]
46024602
[typing fixtures/typing-typeddict.pyi]
46034603

4604+
[case testTypedDictTupleExpressionWithCollectionContext]
4605+
import collections.abc
4606+
from typing import Collection, TypedDict
4607+
4608+
class Item(TypedDict):
4609+
x: int
4610+
4611+
def take(items: Collection[Item]) -> None: ...
4612+
def take_abc(items: collections.abc.Collection[Item]) -> None: ...
4613+
4614+
take(({"x": 1}, {"x": 2}))
4615+
take_abc(({"x": 1}, {"x": 2}))
4616+
items: Collection[Item] = ({"x": 1}, {"x": 2})
4617+
abc_items: collections.abc.Collection[Item] = ({"x": 1}, {"x": 2})
4618+
[builtins fixtures/dict.pyi]
4619+
[typing fixtures/typing-typeddict.pyi]
4620+
46044621
[case testTypedDictAssignableToWiderContext]
46054622
from typing import TypedDict, Union
46064623

test-data/unit/fixtures/typing-typeddict.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Iterable(Protocol[T_co]):
4747
class Iterator(Iterable[T_co], Protocol):
4848
def __next__(self) -> T_co: pass
4949

50+
class Collection(Iterable[T_co]): pass
51+
5052
class Sequence(Iterable[T_co]):
5153
def __getitem__(self, n: Any) -> T_co: pass # type: ignore[explicit-any]
5254

0 commit comments

Comments
 (0)