Код: Выделить всё
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)
Код: Выделить всё
$ 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
Примечание: создание подклассов class A(Iterable[int]) допускает правильное разрешение типов, но вопрос здесь не в этом;)
Подробнее здесь: https://stackoverflow.com/questions/787 ... any-in-zip