mypy vs. pyright
coreintermediatemypy and pyright are static type checkers — separate programs that read your annotations and flag mismatches before the code ever runs. Neither is part of Python itself; both must be installed and run explicitly.
Think of it as
A type checker is a proofreader, not a compiler — it reads the whole file, cross-checks every annotation against every use, and reports what does not add up, without ever executing a single line of your code. mypy is the original, Python-native proofreader; pyright is Microsoft's, built into the Pylance VS Code extension, generally faster and used by more editors out of the box.
What we're doing: Run a deliberately type-incorrect call through both mypy and pyright and compare their real output.
- 4
- "2" and "3" are str, not int — this violates the annotation, but Python itself runs the line without error (it concatenates the strings).
mypy: error: Argument 1 to "add" has incompatible type "str"; expected "int" [arg-type]
mypy: error: Argument 2 to "add" has incompatible type "str"; expected "int" [arg-type]
pyright: error: Argument of type "Literal['2']" cannot be assigned to parameter "a" of type "int" in function "add" (reportArgumentType)
pyright: error: Argument of type "Literal['3']" cannot be assigned to parameter "b" of type "int" in function "add" (reportArgumentType)Why this works: Both tools parse the same source file, build the same understanding of add's signature from its annotations, and independently conclude that "2" (a str) does not match the int parameter — mypy names the general type str, pyright is more precise and names the literal value "2". Neither tool ran add("2", "3"); both analyzed the code without executing it.
Assuming a type checker installed on one machine runs automatically for every contributor
Wrong
Better
What you see: A type error that mypy would have caught instantly ships to production, because the check only ran on the one machine where a developer happened to install and remember to run it.
Why: A type checker installed locally is opt-in and easy to forget — it provides zero protection until it runs somewhere every change must pass through, which is exactly what wiring it into CI (see using-type-checking-in-practice) is for.
- mypy
- pip install mypy — Python-native, the original
- mypy file.py from the command line
- Widely used as the CI standard for typed Python
- pyright
- Microsoft; powers Pylance in VS Code
- npx pyright file.py, or runs live in the editor
- Generally faster; strong editor integration
The same type error, reported by each tool
Together
Remember: mypy and pyright are separate installed tools, not part of Python — both read the same annotations and report mismatches without running the code.
See also: using type checking in practice · basic annotations · mypy and pyright

