mypy

static type checker for Python

TLDR

Type check file
$ mypy [script.py]
Type check directory
$ mypy [src/]
Strict mode
$ mypy --strict [script.py]
Ignore missing imports
$ mypy --ignore-missing-imports [script.py]
Show error codes
$ mypy --show-error-codes [script.py]
Check specific Python version
$ mypy --python-version [3.10] [script.py]
Generate HTML report
$ mypy --html-report [report/] [script.py]

SYNOPSIS

mypy [options] files

DESCRIPTION

mypy is a static type checker for Python. It validates type annotations.The tool catches type errors before runtime. Supports gradual typing adoption.

PARAMETERS

FILES

Python files to check.
--strict
Enable all optional error-checking flags (strict mode).
--ignore-missing-imports
Silence errors about imports that cannot be resolved.
--show-error-codes
Display error codes in messages (default in recent versions).
--python-version X.Y
Type check code as if running on the specified Python version.
--disallow-untyped-defs
Disallow defining functions without type annotations.
--follow-imports MODE
How to handle imports (normal, silent, skip, error).
--html-report DIR
Generate HTML type-check coverage report (requires lxml).
--install-types
Install missing third-party type stubs automatically.
--namespace-packages
Support PEP 420 namespace packages.
--config-file FILE
Use specific mypy configuration file.
--help
Display help information.

INSTALL

sudo pacman -S mypy
sudo apk add py3-mypy
brew install mypy
nix profile install nixpkgs#mypy

CAVEATS

Requires type annotations. Third-party stubs may be needed. Optional strict mode.

HISTORY

mypy was created by Jukka Lehtosalo and is developed at Dropbox as the premier Python type checker.

SEE ALSO

python(1), pyright(1), pylint(1), ruff(1), black(1), flake8(1)