Examples
Here is an example of a mypy.ini
file. To use this config file, place it at the rootof your repo and run mypy.
- # Global options:
- [mypy]
- python_version = 2.7
- warn_return_any = True
- warn_unused_configs = True
- # Per-module options:
- [mypy-mycode.foo.*]
- disallow_untyped_defs = True
- [mypy-mycode.bar]
- warn_return_any = False
- [mypy-somelibrary]
- ignore_missing_imports = True
This config file specifies three global options in the [mypy]
section. These threeoptions will:
- Type-check your entire project assuming it will be run using Python 2.7.(This is equivalent to using the
—python-version 2.7
or-2
flag). - Report an error whenever a function returns a value that is inferredto have type
Any
. Report any config options that are unused by mypy. (This will help us catch typoswhen making changes to our config file). Next, this module specifies three per-module options. The first two options change how mypytype checks code in
mycode.foo.*
andmycode.bar
, which we assume here are two modulesthat you wrote. The final config option changes how mypy type checkssomelibrary
, which weassume here is some 3rd party library you’ve installed and are importing. These options will:Selectively disallow untyped function definitions only within the
mycode.foo
package – that is, only for function definitions defined in themycode/foo
directory.- Selectively disable the “function is returning any” warnings within
mycode.bar
only. This overrides the global default we set earlier. - Suppress any error messages generated when your codebase tries importing themodule
somelibrary
. This is useful ifsomelibrary
is some 3rd party librarymissing type hints.