Skip to content

Importing a new file within a module using "from x import y" fails in incremental mode #1848

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

Closed
Michael0x2a opened this issue Jul 12, 2016 · 2 comments
Labels
bug mypy got something wrong topic-incremental

Comments

@Michael0x2a
Copy link
Collaborator

Consider the following test case:

[case testIncrementalFoo]
from parent import a

[file parent/__init__.py]

[file parent/a.py]

[file parent/a.py.next]
from parent import b

[file parent/b.py.next]

[stale parent.a, parent.b]
[out]

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.

@gvanrossum
Copy link
Member

gvanrossum commented Jul 12, 2016 via email

@Michael0x2a
Copy link
Collaborator Author

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.

Michael0x2a pushed a commit to Michael0x2a/mypy that referenced this issue Jul 14, 2016
Michael0x2a pushed a commit to Michael0x2a/mypy that referenced this issue Jul 14, 2016
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.
@gnprice gnprice added the bug mypy got something wrong label Jul 14, 2016
@gnprice gnprice added this to the 0.4.x milestone Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-incremental
Projects
None yet
Development

No branches or pull requests

3 participants