Use Mypy in pre-commit hooks and CI/CD
Add to the
.pre-commit-config.yaml file in the root of your repository:
repos: - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.730 hooks: - id: mypy exclude: ^tests/ args: [--disallow-untyped-calls, --disallow-untyped-defs, --check-untyped-defs]
Install your git hooks:
pre-commit install # or "autoupdate" if you've already installed previously.
To fail the build if Mypy finds an type error, add the following to your build script.
mypy --disallow-untyped-calls --disallow-untyped-defs --check-untyped-defs --ignore-missing-imports /path/to/code
Mypy will exit with a non-zero exit status if it finds an error, which should fail your build.