Default MyPy type hint checks with .mypy.ini

MyPy is a Python type annotation checker. MyPy recursively checks all files in a Python project by typing:

mypy ~/myproject


We typically use the PyPi MyPy instead of conda, to have the most recent MyPy version:

pip install mypy

Example config

It’s often useful to have a per-project MyPy configuration file to avoid excessive command line options. Put a file .mypy.ini in each Python project containing:

ignore_missing_imports = True
strict_optional = False
allow_redefinition = True
show_error_context = False
show_column_numbers = True

One can make a system-wide ~/.mypy.ini, that is overridden by the per-project .mypy.ini.

isolate problem packages

Sometimes an external package adds type hinting that is incompatible with the current MyPy release. This is relatively rare, but was the case with Xarray. To ignore a package’s type hinting, add the following to .mypy.ini, where we assume we want to ignore xarray type checking.

follow_imports = skip


enhanced mypy usage