Basic usage
Specifying code to check
Files, directories, modules, or packages to type check.
Type check a module by name.
Type check a package and all its submodules.
Type check a program passed as a string.
Configuration file
Specify a configuration file to use.
This flag has the highest precedence and must point to a valid configuration file.
Warn about unused
[mypy-<pattern>] config file sections.Python version and platform
Specify the Python version to target. Format:
MAJOR.MINOR.Specify the platform to check against (e.g.,
linux, darwin, win32).Variables to treat as compile-time constants that are always true.
Variables to treat as compile-time constants that are always false.
Import discovery
Suppress error messages about imports that cannot be resolved.
How to handle imports:
normal: Follow imports and type check themsilent: Follow imports but suppress errorsskip: Don’t follow imports (treat asAny)error: Treat imports as errors
Python executable to use for finding PEP 561 packages.
Do not search for installed PEP 561 packages.
Report errors in installed packages.
Disallow dynamic typing
Disallow
Any types from unfollowed imports.Disallow all expressions that have type
Any.Disallow functions with
Any in signature after decorator transformation.Disallow explicit
Any in type positions.Disallow generic types without explicit type parameters.
Disallow subclassing values of type
Any.Untyped definitions and calls
Disallow calling untyped functions from typed functions.
Exclude specific packages/modules from
--disallow-untyped-calls.Disallow defining functions without type annotations.
Disallow defining functions with incomplete type annotations.
Type check the interior of functions without type annotations.
Disallow decorating typed functions with untyped decorators.
None and Optional handling
Enable strict checking of optional types and
None values.Disable strict optional checking.
Treat arguments with
None default as having optional type.Warnings
Warn about redundant casts.
Warn about unneeded
# type: ignore comments.Don’t warn about missing return statements.
Warn when returning
Any from non-Any function.Warn about unreachable code.
Strictness flags
Enable all optional error checking flags.
This is equivalent to enabling:
--disallow-any-generics, --disallow-untyped-calls, --disallow-untyped-defs, --disallow-incomplete-defs, --check-untyped-defs, --disallow-untyped-decorators, --warn-redundant-casts, --warn-unused-ignores, --warn-return-any, --no-implicit-reexport, --strict-equality, --strict-concatenate, --extra-checksSuppress errors caused by not being able to infer types of global/class variables.
Allow variable redefinition with arbitrary types.
Disallow partial types spanning module top level and function.
Require explicit re-export using
from ... as ... or __all__.Prohibit equality/identity/container checks between non-overlapping types.
Enable additional checks that are technically correct but impractical.
Error codes
Enable specific error codes.
Disable specific error codes.
Error message formatting
Show context in error messages.
Show column numbers in error messages.
Show documentation links for error codes.
Hide error codes in error messages.
Use visually nicer output with soft word wrap and source snippets.
Disable color in error messages.
Hide error summary.
Show absolute paths in error messages.
Incremental mode
Disable incremental mode.
Store cache info in the specified directory.
Use SQLite database for cache storage.
Include fine-grained dependencies in cache.
Use cache even if generated by different Mypy version.
Skip cache internal consistency checks based on mtime.
Reports
Generate a report of
Any expressions.Generate an HTML coverage report.
Generate a line count report.
Generate a JSON line coverage report.
Advanced options
Specify Mypy plugins to use.
Exclude files/directories matching the pattern.
Show more verbose messages.
Invoke debugger on fatal error.
Show traceback on fatal error.
Raise exceptions on fatal errors (for debugging).
Output options
Write a JUnit XML file with type checking results.
Format for JUnit XML output.