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
{{ message }}
Repository navigation
Importing a new file within a module using "from x import y" fails in incremental mode #1848
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.
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).
Activity
gvanrossum commentedon Jul 12, 2016
Michael0x2a commentedon Jul 12, 2016
It seems like making the dummy change does make the problem go away, as you predicted :)
I'll look into the caching logic next then.
Add failing test case demonstrating bug
Correctly handle ImportFrom in incremental mode