-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
mypy running in 3.11 targeting 3.7 reports syntax errors for positional args in numpy #14373
Comments
Recent versions of numpy require Python 3.8 or newer https://github.com/numpy/numpy/blob/68d7aadd30cb7a4f6f32e76715b38b644df18602/setup.py#L435 |
My project doesn’t actually use numpy; numpy just happens to be installed in the python (3.11) I’m using for development. Grepping around, though, my project does import pytest, which can import numpy (optionally, from within a function). Does mypy have to statically follow all imports? Is there a way to force it to skip numpy? |
You can add a per-module follow imports setting. Something like the following in a mypy.ini:
|
Awesome -- I was able to fix this with the following in [[tool.mypy.overrides]]
module = 'pytest'
follow_imports = 'skip' If I tell it to skip I wonder whether, for larger projects, it would make sense to have a follow imports setting to specify a "core" set of packages (i.e. the ones I'm actively developing) and by default only follow imports from them. e.g.: [tool.mypy]
only_follow_imports_from = ['mypackage.*', 'othermodule'] This would get you |
Okay, checked with my laptop. Since numpy ships stubs, apparently you also need to set
|
Bug Report
I'm developing in Python 3.11, but my project targets 3.6-3.11, and we set up mypy to target Python 3.7.
mypy
will fail if I have numpy installed locally.To Reproduce
I actually set this up with
pyproject.toml
and use a Spack environment, but I simplified things with a CLI arg for the reproducer.Expected Behavior
I expected not to get the syntax error, as I don't want to limit what developers have installed in their environment outside my project.
This seems almost like a duplicate of #13639, which was fixed in .980, but I'm targeting 3.7 explicitly and they weren't. So maybe my understanding is incorrect, and if I target 3.7 I'm supposed to get this error. But I feel like I should be able to develop with a newer python and have dev tools target an older one without this issue.
Actual Behavior
Got this error:
Your Environment
--python-version=3.7
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: