DEV Community

TildAlice
TildAlice

Posted on • Originally published at tildalice.io

Python Type Hints: runtime vs typing-only Annotations

Most Python Type Hints Do Absolutely Nothing at Runtime

You add type hints to your Python code, run it, and... nothing happens. No validation. No errors. The annotations just sit there. But some annotations—like dataclasses, Pydantic models, or typing.NewType—actually change how your code behaves. The difference isn't obvious until you hit a production bug that could've been caught if you knew which hints matter when.

The core distinction: typing-only annotations exist purely for static analysis tools like mypy or pyright. Runtime annotations are inspected by libraries or decorators during execution to enforce validation, generate code, or alter behavior. Most developers treat all type hints the same way, then wonder why Pydantic validators catch bugs that mypy missed—or vice versa.

This post runs the same code with different annotation styles, shows what actually happens at runtime, and benchmarks the cost of runtime validation. You'll see real tracebacks, performance numbers from Python 3.11 and 3.12, and the edge cases where mixing both approaches breaks your code.


High-angle view of woman coding on a laptop, with a Python book nearby. Ideal for programming and tech content.


Continue reading the full article on TildAlice

Top comments (0)