Skip to content

Star imports can't be redefined #10563

Open

Description

@srittau

Bug Report

Using mypy 0.820+dev.61c346230cf4960c9766f7c2b5bd3312b47f74da and Python 3.9.4:

# a.py

x: int
# and many more definitions
# b.py

from a import *

x: str  # Name "x" already defined (possibly by an import)
reveal_type(x)  # Revealed type is "builtins.int"

This caused us a lot of trouble in python/typeshed#5545 and leads to this horrible and hard to maintain import mess: https://github.com/python/typeshed/blob/6ee67483a30e178f243d3a9a5b5a9bb4b902901a/stdlib/socket.pyi

I understand the warning and I think it makes sense to have to suppress it with # type: ignore. But the the fact that the override behaves differently from runtime is quite problematic as evidenced by socket.py. This is an example from the standard library that relies on the fact that star imports can be overridden selectively.

Activity

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

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions