Python type hints and mypy: catch bugs before running

11 steps · about 5 h · Intermediate

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. Python Type Checking (Guide) (guide, Real Python, 1 h)

    A thorough walkthrough covering annotations, mypy, stubs and the trade-offs of adopting typing.

  6. 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.

  7. 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.

  8. 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.

  9. pyright: Python Static Type Checker by Microsoft (reference, pydevtools handbook, 10 min)

    Introduces the main alternative checker, so you can compare it with mypy.

  10. 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.

  11. 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.