Description
Filed as follow-up to python/typeshed#1827.
Given the following tree structure:
.
├── real
│ ├── __init__.py
│ └── sub.py
├── stub
│ ├── __init__.pyi
│ └── sub.pyi
└── test.py
with all files empty except for test.py
, which contains:
from stub import noexist1
from stub.sub import noexist2
from stub.noexist3 import noexist4
from real import noexist5
from real.sub import noexist6
from real.noexist7 import noexist8
from noexist9 import bar
from noexist10 import baz
Running mypy --ignore-missing-imports test.py
results in:
test.py:1: error: Module 'stub' has no attribute 'noexist1'
test.py:2: error: Module 'stub.sub' has no attribute 'noexist2'
test.py:5: error: Module 'real' has no attribute 'noexist5'
test.py:6: error: Module 'real.sub' has no attribute 'noexist6'
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
:
[mypy-stub.*]
ignore_missing_imports = True
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.