The following script:
from collections.abc import Iterable, Iterator
class A(Iterable):
_list: list[int]
def __init__(self, *args: int) -> None:
self._list = list(args)
def __iter__(self) -> Iterator[int]:
return iter(self._list)
a = A(1, 2, 3)
for i in a:
reveal_type(i)
for s, j in zip("abc", a):
reveal_type(j)
yields the following mypy output:
$ mypy test.py
test.py:17: note: Revealed type is "builtins.int"
test.py:20: note: Revealed type is "Any"
Success: no issues found in 1 source file
Why is the type Any
when iterating on zip
, but not on the object directly?