Introduction
Mypy is a static type checker for Python 3 and Python 2.7. If you sprinkleyour code with type annotations, mypy can type check your code and find commonbugs. As mypy is a static analyzer, or a lint-like tool, the typeannotations are just hints for mypy and don’t interfere when running your program.You run your program with a standard Python interpreter, and the annotationsare treated effectively as comments.
Using the Python 3 function annotation syntax (using the PEP 484 notation) ora comment-based annotation syntax for Python 2 code, you will be able toefficiently annotate your code and use mypy to check the code for commonerrors. Mypy has a powerful and easy-to-use type system with modern featuressuch as type inference, generics, callable types, tuple types,union types, and structural subtyping.
As a developer, you decide how to use mypy in your workflow. You can alwaysescape to dynamic typing as mypy’s approach to static typing doesn’t restrictwhat you can do in your programs. Using mypy will make your programs easier tounderstand, debug, and maintain.
This documentation provides a short introduction to mypy. It will help youget started writing statically typed code. Knowledge of Python and astatically typed object-oriented language, such as Java, are assumed.
Note
Mypy is used in production by many companies and projects, but mypy isofficially beta software. There will be occasional changesthat break backward compatibility. The mypy development team tries tominimize the impact of changes to user code.