Static type checking in Python with mypy
A tutorial in bullet points
1 min readJul 28, 2019
- using types can prevent mistakes and errors
- type hints were added to Python in version 3.5
- primitive data types like str, int and bool are available without additional imports
- to use lists, optionals or other types, you need to import them
- to check the types, you can use mypy
- to install mypy use: pip install mypy
- to check a single file use: mypy path/to/file.py
- if there is no output, everything was ok
- otherwise all errors are listed
- instead of a single file, all files of a project can be checked as well
- to find all methods without annotations use:
mypy path/to/project --disallow-untyped-defs - More information on mypy:
Type hints cheat sheet and The mypy command line