Skip to content

Synthetic intersections are leaking in star imports #20457

@bzoracler

Description

@bzoracler

Bug Report, To Reproduce, & Actual Behaviour

Synthetic intersections leak in star imports, and if the intersection is created in different modules from the same intersectees, mypy reports "incompatible import" errors.

Run mypy on the following project:

$ mypy
src/pkg/__init__.py:2: error: Incompatible import of "<subclass of "pkg.m3.A" and "pkg.m3.B">" (imported name has type "type[pkg.m2.<subclass of "pkg.m3.A" and "pkg.m3.B">]", local name has type "type[pkg.m1.<subclass of "pkg.m3.A" and "pkg.m3.B">]")  [assignment]

Project:

project/
    mypy.ini
        [mypy]
        files = src/
    src/
        pkg/
            __init__.py
                from .m1 import *
                from .m2 import *
            m1.py
                from .m3 import A, B
                def f() -> None:
                    a: A
                    if isinstance(a, B): ...
            m2.py
                from .m3 import A, B
                def f() -> None:
                    a: A
                    if isinstance(a, B): ...
            m3.py
                class A: ...
                class B: ...
                class AB(A, B): ...

The issue arises from the call to the SymbolTableNode constructor here, which probably should be passed module_public=False.

curr_module.names[full_name] = SymbolTableNode(GDEF, info)

Expected Behavior

No issues

Your Environment

  • Mypy version used: 1.19.1
  • Mypy command-line flags: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions