What stays the same at run time
reveal_type from typing (3.11+) prints the real type to the error stream. cast and TYPE_CHECKING show that checker-only tools leave no mark when running.
A type checker reads your code without running it and reports every place where the hints contradict each other. mypy and pyright are the two most used; you install one, point it at your files, read its messages, and run it in CI so mistakes cannot be merged.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Using mypy on your computer, write a function def half(n: int) -> float: return n / 2 and call half("4"). Say which error code mypy gives.
Make a short program that prints the real type of 3 + 4.5 using typing.reveal_type.
Write the three lines of a pyproject.toml section that turn on mypy strict mode for Python 3.13.
Explain it without notes
What does a type checker do and what does it not do?
What is reveal_type for? How is the typing.reveal_type function different from the checker's one?
When is # type: ignore acceptable, and how should you write it?
Why run a checker in CI as well as in the editor?
How do cast, # type: ignore and an isinstance check differ when you need to convince the checker of a type?
Expected output
TYPE_CHECKING at run time: False
Runtime type is 'int'
value = 42
cast returned: 'not an int' str