Type checkers


Type Checking (The "How")

Type checking is the process of verifying that type hints are being followed. In Python, this almost always happens outside of the actual program execution.

There are two main ways this happens:

A. Static Type Checking (Before you run)

This is done by external tools (linters) like Mypy, Pyright (used by VS Code), or PyCharm.

  • They scan your .py files without actually executing the code.

  • They look for logical inconsistencies (e.g., "You said this returns a string, but here you return a float").

  • This is where the "safety" comes from.

B. Runtime Type Checking (While you run)

Standard Python doesn't do this, but certain libraries "hijack" the hints to enforce them.

  • Pydantic / FastAPI: If you define a hint and send the wrong data type to an API, Pydantic will catch it at runtime and throw a ValidationError.

  • Typeguard: A library you can use to force Python to check types while the code is running (though this slows down performance).

Why the distinction type hinting/type checking matters

Because Python is dynamically typed, the "Checking" part is decoupled from the language itself. This is different from languages like Java or C++, where the "Hinting" and "Checking" are the same thing—the compiler won't even let you finish building the app if the types don't match.

In Python, you can have a perfectly "hinted" codebase that is full of type errors if you never actually run a "Type Checker" against it.


Tools: Pyright, mypy


tyarrow-up-right - type checker written in Rust (not yet production ready). Review: https://www.youtube.com/watch?v=aDViJRLQr30arrow-up-right


Last updated