← 返回命令列表

Linux command

mypy 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

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]

说明

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

参数

--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.

FAQ

What is the mypy command used for?

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

How do I run a basic mypy example?

Run `mypy [script.py]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --strict do in mypy?

Enable all optional error-checking flags (strict mode).