Type your Python like the standard library does.
Implementation-first references for modern typing syntax, strict analyzer setup, and CI gates that scale across production Python teams — grounded in the PEPs and the real behaviour of mypy, pyright, and ruff.
- PEP 604 · 612 · 695
- TypeVar · Protocol · ParamSpec
- mypy · pyright · ruff · pre-commit
from typing import Protocol
class Model(Protocol):
id: int
class Repo[T: Model]:
def get(self, pk: int) -> T:
...
Start with a core area
Three core areas cover the typing system end to end — from everyday annotations to the strict CI gates that keep large codebases honest.
What you'll master
Every guide is tool-aware: code blocks name their Python version and analyzer, and error codes are quoted so you can grep your CI log straight to the fix.
Modern syntax, not legacy
Write X | None, list[str] and PEP 695 class Repo[T] — with the legacy equivalents mapped for older runtimes.
Generics that hold up
TypeVar bounds, variance, Protocols, ParamSpec and overloads — modelled the way static analyzers actually resolve them.
Analyzer divergence, decoded
Where mypy and pyright disagree on narrowing, overloads and TypeGuard — and which flag settles it in your config.
Strict CI, incrementally
pre-commit, GitHub Actions and per-package overrides for rolling out --strict on a legacy codebase without a flag day.
Popular topics
Jump straight to a focused area.
- Python Function Overloading and @overload
- Python Generics and TypeVar: CI Workflows
- ParamSpec and Concatenate for Typed Decorators
- PEP 695 Type Parameter Syntax in Python 3.12
- Python Protocol and Structural Subtyping
- Python typing.Self and typing.NotRequired
- TypeGuard & TypeIs: User-Defined Type Narrowing
- Variance: Covariance, Contravariance & Invariance
- Python Type Aliases: Syntax & CI
- Python Callable Signatures Type Hints
- Python typing.Literal and TypedDict Guide
- Python Union and Optional Types Guide
- Running mypy & pyright in GitHub Actions
- Incremental Typing in a Python Monorepo
- Mypy Configuration & Strictness Guide
- Pre-commit Hooks for Python Typing
- Pyright vs Mypy: Architecture & CI
- Ruff Linter Integration for Python