How to annotate a generator in Python 3?
While Generator[x, y, z] exists, most of the time, you might want to use the less verbose Iterator: def fn(x: int) -> Iterator[int]: return (n for n in range(x) if n%2 == 0) Also works for yield def fn(x: int) -> Iterator[int]: for n in range(x): yield n