ID EN
Typing

Generator

Python 3.11

Deprecated alias to collections.abc.Generator.

Syntax

PYTHON
class typing.Generator(Iterator[YieldType], Generic[YieldType, SendType, ReturnType])

Examples

Example 1
PYTHON
def echo_round() -> Generator[int, float, str]:
    sent = yield 0
    while sent >= 0:
        sent = yield round(sent)
    return 'Done'
Example 2
PYTHON
def infinite_stream(start: int) -> Generator[int, None, None]:
    while True:
        yield start
        start += 1
Example 3
PYTHON
def infinite_stream(start: int) -> Iterator[int]:
    while True:
        yield start
        start += 1

See Also

collections.abc.Generator Generator collections.abc.Generator Generic Alias Type