On this page
  1. typing.Generator
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

typing.Generator

Prev: typing.FrozenSet | Up: typing | Next: typing.Generic
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.Generator
Tags: #public #python3 #stdlib #typing


Import

import typing
from typing import Generator

Signature & Overview

typing.Generator(*args, **kwargs)

Deprecated alias to collections.abc.Generator.

Usage

from typing import Generator

def squares(n: int) -> Generator[int, None, None]:
    for i in range(n):
        yield i * i

assert list(squares(3)) == [0, 1, 4]

Gotchas

REPL Inspect

from typing import Generator
help(Generator)

Linked from

Related notes