Type checkers
What is mypy? An introduction to the Python Project (mypy) optional static type checker
Mypy is an optional static type checker for Python that combines dynamic and static typing. It checks type annotations that conform to PEP 484 and can infer the types of many variables. Programs can start dynamically typed and gain static typing later.
- Tool
- mypy
- Made by
- Python Project (mypy)
- Official site
- mypy-lang.org
- Category
- Type checkers
Who makes mypy
Mypy is made by the Python Project (mypy). Jukka Lehtosalo began work on mypy in 2012, and its design was influenced by gradual typing research and several programming languages.
The official website, mypy-lang.org, is linked below.
Official website: mypy-lang.org
What mypy is for
Mypy is for finding bugs in Python code before it runs. Static typing helps find bugs with less debugging, because mismatches between what code expects and what it receives surface as type errors rather than runtime failures.
It also makes code easier to understand. Type declarations serve as machine-checked documentation, so unlike a comment, they cannot quietly drift out of date without the checker noticing.
Typing in mypy is optional. Programs can start dynamically typed and gain static typing later, which means nobody has to annotate everything up front to get value from the tool.
Who mypy is for
The vendor describes the audience as Python developers. That covers people writing new Python code with annotations from the start and people maintaining existing code that has none.
The incremental model matters most for the second group. Code can be migrated incrementally, mixing static and dynamic typing, so a codebase can adopt types module by module rather than all at once.
Notable capabilities
Mypy pairs a modern type system with a gradual approach to adoption. These are the capabilities it documents.
- Optional static checking: it is an optional static type checker, so annotations are added where they are wanted.
- Gradual typing: programs can start dynamically typed and gain static typing later.
- Incremental migration: code can be migrated incrementally, mixing static and dynamic typing.
- Type inference: it can infer types of variables, often needing only function signatures.
- PEP 484 support: it checks annotations conforming to PEP 484.
- Modern type system: it has a modern type system with inference, generics and more.
- Library stubs: library stubs let mypy check correct library usage.
- Low runtime cost: programs run on any Python VM with basically no runtime overhead.
How mypy fits type checkers
Type checkers analyze code for type consistency without running it. Mypy is a type checker built specifically for Python, designed around the idea that typing can be optional and added gradually.
In Linthelm's wider niche of linters, static analysis and code quality, type checkers sit between style linters and deeper analysis. A linter asks whether code follows conventions, while mypy asks whether values are used in ways their declared types allow. Both inspect code statically, and both aim to catch problems before they reach production.
Because annotations are checked rather than enforced at runtime, mypy adds its value at review and build time while leaving how the program runs unchanged.
Frequently asked questions
What is mypy used for?
Mypy is used to statically type check Python code. Static typing helps find bugs with less debugging, and type declarations serve as machine-checked documentation.
Is static typing required with mypy?
No. Mypy is an optional static type checker, and programs can start dynamically typed and gain static typing later. Code can also be migrated incrementally, mixing static and dynamic typing.
Does mypy slow down Python programs?
Programs run on any Python VM with basically no runtime overhead.
Does mypy support PEP 484?
Yes. Mypy checks annotations conforming to PEP 484 and has a modern type system with inference, generics and more.
Who created mypy?
Jukka Lehtosalo began work on mypy in 2012. Its design was influenced by gradual typing research and several languages.
Linthelm is independent and is not affiliated with Python Project (mypy). Product names belong to their owners. Features change; confirm details on the official website.