You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It initially starts with two files (parent/__init__.py and parent/a.py) that are both empty, then runs mypy -i -c "from parent import a" to warm up the cache.
We then add a new empty file, parent/b.py, and change parent/a.py to contain the single line from parent import b and re-run mypy -i -c "from parent import a".
The expected behavior is that mypy should typecheck the modified files without complaining, but will instead report the following error:
<string>:1: note: In module imported here:
parent/a.py:1: error: Module has no attribute 'b'
This error disappears when we change parent/a.py to contain either the line import parent.b or import parent.b as b, or if the file parent/b.py existed before mypy was first run.
The text was updated successfully, but these errors were encountered:
Good find! I suspect the key to this issue is the ambiguity inherent in
`from parent import b`. This can either import an attribute defined in
`parent/__init__.py` or a submodule `parent/b.py`. I expect that if you
make some dummy change to `__init__.py` to force it to change that will
also make the problem go away -- if that's so, the solution probably
involves throwing away the cache data for `parent/__init__.py` when a
module is added (or removed).
This pull request makes mypy re-parse __init__.py files within modules
when a new file is added to that module before incremental mode is run a
second time.
Previously, when a file was modified to contain a new "from x import y"
where "y" is the newly created submodule, mypy would assume that "y" was
instead a new attribute added to the "x" module.
See python#1848 for more details.
Consider the following test case:
It initially starts with two files (
parent/__init__.py
andparent/a.py
) that are both empty, then runsmypy -i -c "from parent import a"
to warm up the cache.We then add a new empty file,
parent/b.py
, and changeparent/a.py
to contain the single linefrom parent import b
and re-runmypy -i -c "from parent import a"
.The expected behavior is that mypy should typecheck the modified files without complaining, but will instead report the following error:
This error disappears when we change
parent/a.py
to contain either the lineimport parent.b
orimport parent.b as b
, or if the fileparent/b.py
existed before mypy was first run.The text was updated successfully, but these errors were encountered: