summaryrefslogtreecommitdiff
path: root/pyproject.toml
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2022-12-31 17:05:17 -0800
committerGitHub <noreply@github.com>2023-01-01 01:05:17 +0000
commitca265ea0c268d1be05c85e66b25916e0d8c85932 (patch)
treea5413e20e544e013e5848da3be2d288c06a27f49 /pyproject.toml
parent7a925794806846919ba71b6d30e308297731ced0 (diff)
downloadspack-ca265ea0c268d1be05c85e66b25916e0d8c85932.tar.gz
spack-ca265ea0c268d1be05c85e66b25916e0d8c85932.tar.bz2
spack-ca265ea0c268d1be05c85e66b25916e0d8c85932.tar.xz
spack-ca265ea0c268d1be05c85e66b25916e0d8c85932.zip
style: fix spurious `mypy` errors from `numpy` (#34732)
Spack imports `pytest`, which *can* import `numpy`. Recent versions of `numpy` require Python 3.8 or higher, and they use 3.8 type annotations in their type stubs (`.pyi` files). At the same time, we tell `mypy` to target Python 3.7, as we still support older versions of Python. What all this means is that if you run `mypy` on `spack`, `mypy` will follow all the static import statements, and it ends up giving you this error when it finds numpy stuff that is newer than the target Python version: ``` ==> Running mypy checks src/spack/var/spack/environments/default/.spack-env/._view/4g7jd4ibkg4gopv4rosq3kn2vsxrxm2f/lib/python3.11/site-packages/numpy/__init__.pyi:638: error: Positional-only parameters are only supported in Python 3.8 and greater [syntax] Found 1 error in 1 file (errors prevented further checking) mypy found errors ``` We can fix this by telling `mypy` to skip all imports of `numpy` in `pyproject.toml`: ```toml [[tool.mypy.overrides]] module = 'numpy' follow_imports = 'skip' follow_imports_for_stubs = true ``` - [x] don't follow imports from `numpy` in `mypy` - [x] get rid of old rule not to follow `jinja2` imports, as we now require Python 3
Diffstat (limited to 'pyproject.toml')
-rw-r--r--pyproject.toml9
1 files changed, 6 insertions, 3 deletions
diff --git a/pyproject.toml b/pyproject.toml
index 512d48546e..dda109cff5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -141,11 +141,14 @@ ignore_missing_imports = true
ignore_errors = true
ignore_missing_imports = true
- # jinja has syntax in it that requires python3 and causes a parse error
- # skip importing it
+ # pytest (which we depend on) optionally imports numpy, which requires Python 3.8 in
+ # recent versions. mypy still imports its .pyi file, which has positional-only
+ # arguments, which don't work in 3.7, which causes mypy to bail out early if you have
+ # numpy installed.
[[tool.mypy.overrides]]
- module = 'jinja2'
+ module = 'numpy'
follow_imports = 'skip'
+ follow_imports_for_stubs = true
[tool.pyright]
useLibraryCodeForTypes = true