Python type hints and mypy: catch bugs before running
11 steps · about 5 h · Intermediate
- Python Type Hints (tutorial, Python Tutorial, 20 min)
A short first look at annotation syntax and running mypy, so the rest of the list has a base.
- A Complete Guide to Python Type Hints (guide, Better Stack, 30 min)
It shows that hints don't change runtime behavior and that mypy catches mistakes before the code runs.
- Getting started - mypy documentation (doc, mypy docs, 25 min)
The official explanation of static versus dynamic typing, inference and strict mode, read once you've tried the basics.
- Type hints cheat sheet (reference, mypy docs, 20 min)
A compact reference for common annotations and for reveal_type(), which you'll use while practicing.
- Python Type Checking (Guide) (guide, Real Python, 1 h)
A thorough walkthrough covering annotations, mypy, stubs and the trade-offs of adopting typing.
- Python Type Hints A Deep Dive into typing and MyPy (blog, Leapcell, 25 min)
Moves on to Optional values, Any, Protocols, generics and configuring mypy via pyproject.toml.
- Python Protocols: Leveraging Structural Subtyping (tutorial, Real Python, 30 min)
Explains Protocols, which let you type duck-typed code without inheritance, a common next hurdle.
- Typed dictionaries — typing documentation (reference, typing.python.org, 20 min)
The authoritative spec for typing dict-shaped data such as JSON, including required keys and generics.
- pyright: Python Static Type Checker by Microsoft (reference, pydevtools handbook, 10 min)
Introduces the main alternative checker, so you can compare it with mypy.
- mypy documentation (doc, mypy docs, 45 min)
Covers the type system reference, error codes and the guide to using mypy on an existing codebase, for real projects.
- GitHub - python/mypy: Optional static typing for Python (repo, python/mypy on GitHub, 15 min)
The source repo and issue tracker, useful for questions and for following how the checker evolves.