Skip to content

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

@Michael0x2a

Description

@Michael0x2a

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions