Mypy : a program that will type check your Python code.

../../_images/logo_mypy.svg

Definition 1 : What is mypy ?

Mypy is an optional static type checker for Python.

You can add type hints ( PEP 484 ) to your Python programs, and use mypy to type check them statically.

Find bugs in your programs without even running them !

You can mix dynamic and static typing in your programs.

You can always fall back to dynamic typing when static typing is not convenient, such as for legacy code.

Here is a small example to whet your appetite (Python 3)

1 from typing import Iterator
2
3 def fib(n: int) -> Iterator[int]:
4     a, b = 0, 1
5     while a < n:
6         yield a
7         a, b = b, a + b

Definition 2

Mypy is an experimental optional static type checker for Python that aims to combine the benefits of dynamic (or “duck”) typing and static typing.

Mypy combines the expressive power and convenience of Python with a powerful type system and compile-time type checking.

Mypy type checks standard Python programs; run them using any Python VM with basically no runtime overhead.

Mypy is still in development. Most Python features are supported.

Mypy blog

Mypy Help

Mypy documentation

Mypy stubs

Python Typing Tutorial