LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

mypy

static type checker for Python

TLDR

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

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.

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)

Copied to clipboard
Kai