Skip to content

Commit

Permalink
mypy: add more ignored modules to pyproject.toml (spack#38769)
Browse files Browse the repository at this point in the history
`mypy` will check *all* imported packages, even optional dependencies outside your
project, and this can cause issues if you are targeting python versions *older* than the
one you're running in. `mypy` will report issues in the latest versions of dependencies
as errors even if installing on some older python would have installed an older version
of the dependency.

We saw this problem before with `numpy` in spack#34732. We've started seeing it with IPython
in spack#38704. This fixes the issue by exempting `IPython` and a number of other imports of
Spack's from `mypy` checking.
tgamblin authored Jul 11, 2023
1 parent f0ef0ce commit 162d092
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -141,12 +141,29 @@ ignore_missing_imports = true
ignore_errors = true
ignore_missing_imports = true

# 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.
# Spack imports a number of external packages, and they *may* require Python 3.8 or
# higher in recent versions. This can cause mypy to fail because we check for 3.7
# compatibility. We could restrict mypy to run for the oldest supported version (3.7),
# but that means most developers won't be able to run mypy, which means it'll fail
# more in CI. Instead, we exclude these imported packages from mypy checking.
[[tool.mypy.overrides]]
module = 'numpy'
module = [
'IPython',
'altgraph',
'attr',
'boto3',
'botocore',
'distro',
'jinja2',
'jsonschema',
'macholib',
'markupsafe',
'numpy',
'pyristent',
'pytest',
'ruamel.yaml',
'six',
]
follow_imports = 'skip'
follow_imports_for_stubs = true

0 comments on commit 162d092

Please sign in to comment.