-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot suppress python_version-related errors in third-party code #9972
Comments
I have a hard time understanding how this is a bug. With |
@JelleZijlstra: if it's not a bug, then i'm not sure how the The default mypy settings ignore errors in site-packages. The fact that If that's Working As Intended, then yeah, we might as well just close this. |
I see, I guess the issue may be that the error you see is classified as a blocking error, and blocking errors in site-packages are not ignored. |
This comment has been minimized.
This comment has been minimized.
@JelleZijlstra: yeah that sounds right. @volans-: I don't think this is related, as it also happens with older versions of mypy. |
I think this is the same issue as #14373, but there I was able to resolve it with a module-specific override: [[tool.mypy.overrides]]
module = 'pytest'
follow_imports = 'skip'
RE: @JelleZijlstra:
I do think it's going to be harder to avoid this type of error as more projects ship with newer type info. I don't think I should have to add exclusions for (potentially) every conditional import in my transitive dependencies, just to allow developers working in newer python versions to run It would be nice if there were some |
@tgamblin I think you can just skip numpy alone (so you don't need to figure out what's importing it), see #14373 (comment) . Also I think master mypy is better at skipping analysis of things it might not need, so e.g. |
@hauntsaninja I wasn't able to skip numpy alone to make this work: > grep -A 4 'with numpy' pyproject.toml
# fix python version errors with numpy
[[tool.mypy.overrides]]
module = 'numpy'
follow_imports = 'skip'
follow_imports_for_stubs = false
> spack style --tool mypy
==> Running style checks on spack
selected: mypy
==> Running mypy checks
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
==> Error: spack style found errors vs. > grep -A 4 'with numpy' pyproject.toml
# fix python version errors with numpy
[[tool.mypy.overrides]]
module = 'pytest'
follow_imports = 'skip'
follow_imports_for_stubs = false
> spack style --tool mypy
==> Running style checks on spack
selected: mypy
==> Running mypy checks
Success: no issues found in 578 source files
mypy checks were clean
==> spack style checks were clean This is with 0.991, but I haven't tried |
You need |
Ok that does work! The sense of those options is... kind of confusing. So I think this is way better, as I only have to know that Are there some best practices for when you should use |
Yup, you have that right :-) I typically set If it's any comfort, in my experience, it's rare for users to run into the issue you ran into. If you do need something more foolproof, I'd run mypy with Python 3.7. This would avoid the error you ran into, because you'd backsolve to an older numpy that supported Python 3.7 and then not have this issue. |
Patch Set 2: I've filed python/mypy#9972 with upstream. Patch-set: 2
I do not believe skipping imports is a solution. You could be using the 3rd party module API incorrectly and mypy would no longer flag it up, right? |
Bug Report
If i have
python_version = 3.5
set, it's not possible to tell mypy to ignore related syntax errors it finds in dependencies.Use case: i have code which needs to support python 3.5, as well as newer versions. I run mypy against it under various versions of python, with
python_version = 3.5
set so that i don't accidentally introduce something which is incompatible (like variable annotations) which might not get caught until later. This has worked fine until some of the dependencies have started using variable annotations.To Reproduce
pip install mypy importlib-metadata
# Using importlib-metadata as an example lib which uses variable annotationssetup.cfg
with:test.py
with:mypy test.py
Expected Behavior
mypy should enforce
python_version = 3.5
fortest.py
, but it should ignore any version-related issues inimportlib_metadata
.Actual Behavior
mypy fails with:
mypy doesn't seem to treat this as a 'fatal' error, either, as setting
pdb = True
has no effect.Your Environment
The text was updated successfully, but these errors were encountered: