18.9. Typing Iterator
All Generators are Iterators
18.9.1. SetUp
Import from
typingorcollections.abccollections.abcshould be preferred
>>> from typing import Iterator
>>> from collections.abc import Iterator
18.9.2. Iterator
Iterator[yield_type]
>>> def run() -> Iterator:
... yield 1
>>> def run() -> Iterator[int]:
... yield 1
18.9.3. Further Reading
Since Python 3.9: PEP 585 -- Type Hinting Generics In Standard Collections
https://docs.python.org/3/library/typing.html#typing.Iterable