18.9. Typing Iterator

  • All Generators are Iterators

18.9.1. SetUp

  • Import from typing or collections.abc

  • collections.abc should 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