Import discovery

The following flags customize how exactly mypy discovers and followsimports.

  • —namespace-packages
  • This flag enables import discovery to use namespace packages (seePEP 420). In particular, this allows discovery of importedpackages that don’t have an init.py (or init.pyi)file.

Namespace packages are found (using the PEP 420 rules, whichprefers “classic” packages over namespace packages) along themodule search path – this is primarily set from the source filespassed on the command line, the MYPYPATH environment variable,and the mypy_path config option.

Note that this only affects import discovery – for modules andpackages explicitly passed on the command line, mypy stillsearches for init.py[i] files in order to determine thefully-qualified module/package name.

  • —ignore-missing-imports
  • This flag makes mypy ignore all missing imports. It is equivalentto adding # type: ignore comments to all unresolved importswithin your codebase.

Note that this flag does not suppress errors about missing namesin successfully resolved modules. For example, if one has thefollowing files:

  1. package/__init__.py
  2. package/mod.py

Then mypy will generate the following errors with —ignore-missing-imports:

  1. import package.unknown # No error, ignored
  2. x = package.unknown.func() # OK. 'func' is assumed to be of type 'Any'
  3.  
  4. from package import unknown # No error, ignored
  5. from package.mod import NonExisting # Error: Module has no attribute 'NonExisting'

For more details, see Missing imports.

  • —follow-imports {normal,silent,skip,error}
  • This flag adjusts how mypy follows imported modules that were notexplicitly passed in via the command line.

The default option is normal: mypy will follow and type checkall modules. For more information on what the other options do,see Following imports.

  • —python-executable EXECUTABLE
  • This flag will have mypy collect type information from PEP 561compliant packages installed for the Python executable EXECUTABLE.If not provided, mypy will use PEP 561 compliant packages installed forthe Python executable running mypy.

See Using installed packages for more on making PEP 561 compliant packages.

  • —no-site-packages
  • This flag will disable searching for PEP 561 compliant packages. Thiswill also disable searching for a usable Python executable.

Use this flag if mypy cannot find a Python executable for the version ofPython being checked, and you don’t need to use PEP 561 typed packages.Otherwise, use —python-executable.

  • —no-silence-site-packages
  • By default, mypy will suppress any error messages generated within PEP 561compliant packages. Adding this flag will disable this behavior.