-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
ignore-missing-imports does not suppress missing imports from existing modules #4515
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
Comments
The problem here is how would you distinguish between an attribute that's
somehow missing from the stub and a typo in an attribute name? And
technically it's not a missing import (which really refers to the situation
where a module is not found) but a missing attribute.
I agree it's a pain though, and any suggestion you have on how to suppress
such errors with the most precision would be appreciated!
|
How is the "it could be a typo" argument different for module attributes than for module names themselves? Losing this typo protection is just a built-in cost of choosing to apply Not sure about the semantic technicalities, I think a lot of people would call a missing attribute error specifically in the context of a I'm not proposing that "module has no attribute X" errors in any other context should be suppressed. I guess that is slightly weird (and still means some One alternative that could suppress both |
One option would be to spell it |
I guess we look at this from different angles. I am looking at it from the POV of how the import is processed -- if the stub is found in my view it's no longer import's problem. (Even though it's spelled using But I'm fine with an option to change that default. It would be a nice touch if it only applied to stubs since then you can set it globally, but you should also be able to set it for a specific package or module, and then it should apply to all imports from that module/package (not all imports in that package). |
and it will suppress the import of the stub and assume any for all its contents. I'm closing this issue because I think that is a satisfactory solution here, but if somebody disagrees feel free to reopen. |
Filed as follow-up to python/typeshed#1827.
Given the following tree structure:
with all files empty except for
test.py
, which contains:Running
mypy --ignore-missing-imports test.py
results in:That is, missing module errors are suppressed, but imports of missing attributes of existing modules are not suppressed.
This makes incomplete stubs more troublesome than they would otherwise be, because you can't suppress them globally with something like this in
mypy.ini
:There is no option but to either extend the incomplete stub, or else apply individual
# type: ignore
to every single erroring import.It seems to me that the name
ignore-missing-imports
implies that all errors due to importing something that doesn't exist should be suppressed; it shouldn't matter whether the thing that is missing is an entire module or an attribute of a module. So I think this is a bug.All behaviors above checked on current mypy master, Python 3.6.
The text was updated successfully, but these errors were encountered: