Skip to content

Commit cec8b48

Browse files
committed
Recognize Iterator as Hashable
1 parent ed90eaf commit cec8b48

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

mypy/typeshed/stdlib/typing.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ class Iterator(Iterable[_T_co], Protocol[_T_co]):
550550
@abstractmethod
551551
def __next__(self) -> _T_co: ...
552552
def __iter__(self) -> Iterator[_T_co]: ...
553+
def __hash__(self) -> int: ...
553554

554555
@runtime_checkable
555556
class Reversible(Iterable[_T_co], Protocol[_T_co]):

test-data/unit/check-protocols.test

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,14 +1025,17 @@ main:15: note: def [T2] a(self, other: P1[T2]) -> Any
10251025

10261026
[case testHashable]
10271027

1028-
from typing import Hashable, Iterable
1028+
from typing import Hashable, Iterable, Iterator
10291029

10301030
def f(x: Hashable) -> None:
10311031
pass
10321032

10331033
def g(x: Iterable[str]) -> None:
10341034
f(x) # E: Argument 1 to "f" has incompatible type "Iterable[str]"; expected "Hashable"
10351035

1036+
def h(x: Iterator[str]) -> None:
1037+
f(x)
1038+
10361039
[builtins fixtures/object_hashable.pyi]
10371040
[typing fixtures/typing-full.pyi]
10381041

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class Iterable(Protocol[T_co]):
8484
class Iterator(Iterable[T_co], Protocol):
8585
@abstractmethod
8686
def __next__(self) -> T_co: pass
87+
def __hash__(self) -> int: pass
8788

8889
class Generator(Iterator[T_co], Generic[T_co, S_contra, R_co]):
8990
@abstractmethod

0 commit comments

Comments
 (0)