Skip to content

Instantly share code, notes, and snippets.

@stroxler
Last active January 24, 2022 21:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stroxler/ade7977ed07e27448222a468796bc467 to your computer and use it in GitHub Desktop.
Save stroxler/ade7977ed07e27448222a468796bc467 to your computer and use it in GitHub Desktop.
The Most Discoverable Python Typing Tutorials, Etc (circa 2022/01)

This gist is a collection of all the easy-to-find online resources for using typed python as of 2022/01. I collected these notes for two reasons:

  • As an aside in an extensive python-dev typing discussion, Guido mentioned that it would be helpful
  • There’s an active but very slow-moving effort to write official python type system docs in python/typing, and I figured having an easy to skim list of the best existing discussions would be handy.

The official documentation

The official python typing docs web source are very much in construction.

Much of the knowledge about typing patterns is tribal rather than documented, the typing repo discussions have quite a bit of Q&A about how to use types.

The typing module docs are reasonably good, but very much just a reference.

The closest thing to complete documentation at the moment is the mypy docs page.

The other type checker docs generally don’t cover the type system itself in detail:

  • pyre has a very short discussion of “Types in Python” and some helpful details in the errors page (which catalogues every error code and tries to provide an example).
  • pyright docs mainly describing behavior of various “advanced” cases
  • pytpye describes how its behavior differs from mypy

Results of google searches

I looked at the top results of the following Google queries on 2022/01/26:

  • “how to write typed python”
  • “using type annotations python”
  • “effective typed python”
  • “effective python annotations”

The following seraches didn’t show anything relevant at all in the first few pages:

  • “typed python design patterns”

The following are the most useful documentation-style resources I found:

  • RealPython.com: Python Type Checking
    • Other than the MyPy docs I think this is the most detailed guide I found:
      • It covers most of the basic PEP 484 features
    • The mypy docs are more reference than tutorial, this is probably the best tutorial-form resource out there.
  • LogRocket blog This is the most up-to-date and complete of the blogs I found
    • It covers an impressive number of the features of typing
    • This is probably the second-best tutorial-style guide I’ve found.
  • 20 Type Hinting Tricks and Tools (medium paywall)
    • This blog actually has many details. It benefits from not trying to be complete.
    • It discusses not only typing patterns but the various static and dynamic typing tools.

A few additional top hits are not very tutorial-like, but still interesting:

Several more blogs and tutorials that were reasonably well-written but too short to contain very much information also came up in the top search results.

Additional resources (that did not come up in the Google results)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment