Back to search

Type hints: `Optional`, `Union`, `Literal`, `Any`, generics, `Protocol`, and type checking tools

Type hints document intent, improve tooling, and can express unions, optional values, generics, literal constraints, protocols, and escape hatches like `Any`.

Python Hard Theory

Type hints: `Optional`, `Union`, `Literal`, `Any`, generics, `Protocol`, and type checking tools

Type hints document intent, improve tooling, and can express unions, optional values, generics, literal constraints, protocols, and escape hatches like `Any`.

  • Hints help humans and tools
  • `Protocol` supports structural typing
  • Mypy and Pyright are common static type checkers

Type hints: `Optional`, `Union`, `Literal`, `Any`, generics, `Protocol`, and type checking tools