You’ll be able to
- Annotate function signatures with parameter and return types
- Use generic types from
typing:List,Dict,Optional - Validate hints at development time with
mypyor Pyright - Recognize that type hints do not enforce types at runtime
Loading lesson…
Why this matters
Pydantic, FastAPI, and SQLModel do runtime schema generation directly from typing annotations — a wrong Optional[int] versus int | None can silently change API validation. Staff engineers run mypy --strict in CI and use TypeVar, Protocol, and ParamSpec to type generic decorators without losing signatures.
Common pitfalls
- Writing
List[int] = []as a default — mutable default trap; useOptional[List[int]] = Noneand init inside. - Confusing
Optional[X]withX = None—Optionalonly marks nullability, it doesn't set the default. - Skipping
from __future__ import annotationson Python <3.10 — forward references andX | Ysyntax break at runtime.