PyVista's pre-commit
hook for running mypy
.
For pre-commit, see https://github.com/pre-commit/pre-commit
For mypy, see https://github.com/python/mypy
This fork alters the default configuration of the https://github.com/pre-commit/mirrors-mypy hook. It:
- Removes the "mirror" part so that the release version of this hook is no longer tied to the Mypy version.
Instead, the Mypy version is controlled via
additional_dependencies
. This allows users to manually control the version in theirpre-commit-config.yaml
file instead of requiring a new release of this hook to update it. - Removes the default args
["--ignore-missing-imports", "--scripts-are-modules"]
so that users have full control over the arguments passed tomypy
. In particular, the use of--ignore-missing-imports
is discouraged by themypy
developers. - Uses
pass_filenames: false
, which is recommended by themypy
developers.
Add this to your .pre-commit-config.yaml
- repo: https://github.com/pyvista/pre-commit-mypy
rev: v0.1
hooks:
- id: mypy
args: [] # Recommend leaving this blank. Set args via 'pyproject.toml' or 'mypy.ini' instead.
additional_dependencies:
# Recommend duplicating dependencies for your project (e.g. from 'pyproject.toml')
- mypy<1.14.0 # Make sure `mypy` is included
- matplotlib<3.9.3
- typing-extensions<4.13.0
- scipy<1.15.0
- # include any other dependencies here
Recommended configuration:
- Leave
args
blank and use a configuration file instead to control the arguments passed tomypy
. E.g. set these viapyproject.toml
ormypy.ini
. See https://mypy.readthedocs.io/en/stable/config_file.html for details. - Keep
addtional_dependencies
synchronized with all of your project's dependencies, e.g. frompyproject.toml
.
Following these recommendations ensures that running mypy
with the pre-commit hook performs exactly the same analysis as
running mypy
directly.
Note that using the --install-types
option is problematic and should not be included in your mypy configuration. Mutating the pre-commit
environment at runtime breaks cache and will break parallel builds.