Skip to content

Can't redefine name imported from another module #591

Closed

Description

@JukkaL

It should be possible to redefine a name imported from another module, at least in stubs. Currently mypy complains about the redefinition (at least often). We can treat this as an assignment and just verify that the types are compatible.

Activity

  1. gvanrossum commented on Jan 27, 2016

    @gvanrossum
    Member

    (Another one related to #649.)

  2. JukkaL commented on May 17, 2018

    @JukkaL
    CollaboratorAuthor

    I couldn't easily come up with an example that would fail, so I'm closing this. If some special case is still failing we can create a separate issue about that special case.

  3. DanAlbert commented on Mar 26, 2025

    @DanAlbert

    #1168 was duped into this which had an example:

    try:
        from zlip import decompress
    except ImportError:
        def decompress(val):
            raise RuntimeError

    It's still a problem with mypy 1.15.0. Is there a different way we should be writing code that relies on types from maybe-available packages?

  4. DanAlbert commented on Mar 26, 2025

    @DanAlbert

    Actually after commenting I see the case I'm running into is slightly different:

    try:
        from rich.progress import TaskID
    
        def foo(task_id: TaskID) -> None:
            ...
    
    except ModuleNotFoundError:
        def foo(task_id: int) -> None:
            ...

    Which yields "All conditional function variants must have identical signatures", which is the same error, but possibly not the same problem.

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