Skip to content

Regression: submodule access only generates an error with warm cache #20174

@JukkaL

Description

@JukkaL

This incremental mode test case (added to check-incremental.test) started generating a false positive after e1643ae:

[case testIncrementalAccessSubmoduleWithoutExplicitImport]
import b
import a

[file a.py]
import pkg

pkg.submod.foo()

[file a.py.2]
import pkg

pkg.submod.foo()
x = 1

[file b.py]
import c

[file c.py]
from pkg import submod

[file pkg/__init__.pyi]
[file pkg/submod.pyi]
def foo() -> None: pass

It fails like this:

---------------------------------------------------- Captured stderr call ----------------------------------------------------
Expected:
Actual:
  tmp/a.py:3: error: "object" has no attribute "submod" (diff)

On the previous commit (9c26271) the test passes.

This also generated false positives in an internal codebase at work when we tried using a recent mypy development version.

The original behavior is questionable, but different semantics in incremental and non-incremental modes is a much bigger issue.

Credits to @p-sawicki for finding the commit that introduced this.

cc @ilevkivskyi

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions