Skip to content

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

Closed

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.

Activity

  1. gvanrossum commented on Jul 12, 2016

    @gvanrossum
    Member
  2. Michael0x2a commented on Jul 12, 2016

    @Michael0x2a
    CollaboratorAuthor

    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.

  3. added this to the milestone on Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions