Skip to content

Can't redefine name imported from another module #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JukkaL opened this issue Feb 28, 2015 · 4 comments
Closed

Can't redefine name imported from another module #591

JukkaL opened this issue Feb 28, 2015 · 4 comments
Labels
bug mypy got something wrong

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 28, 2015

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.

@gvanrossum
Copy link
Member

(Another one related to #649.)

@JukkaL
Copy link
Collaborator Author

JukkaL commented May 17, 2018

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.

@JukkaL JukkaL closed this as completed May 17, 2018
@DanAlbert
Copy link

DanAlbert commented Mar 26, 2025

#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?

@DanAlbert
Copy link

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
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants