Annotate Python with type hints and check it with mypy
8 steps · about 2 h 50 min · Intermediate
- Read the original type hints proposal (article, Python PEPs, 30 min)
Explains why annotations exist and the rules every checker follows.
- Run mypy on your first file (article, mypy docs, 20 min)
Shows how to install mypy and read its first error messages.
- Keep the type hints cheat sheet nearby (article, mypy docs, 15 min)
A compact reference for common annotations you will write daily.
- Write generic functions and classes (article, mypy docs, 25 min)
Teaches TypeVar and generic containers so helpers keep precise types.
- Describe behaviour with protocols (article, mypy docs, 25 min)
Shows structural typing so you can type duck-typed code without inheritance.
- Fix the most common mypy errors (article, mypy docs, 20 min)
Prepares you for Optional, None checks and untyped-definition complaints.
- Introduce types into an existing codebase (article, mypy docs, 20 min)
Gives a gradual plan for typing a project that already runs.
- Configure strictness in mypy.ini (article, mypy docs, 15 min)
Lets you lock in your progress with per-module strictness settings.