Skip to content

Allow identical classes to be imported twice #2139

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

Merged

Conversation

Michael0x2a
Copy link
Collaborator

This pull request fixes #2135.

Previously, if you attempted importing two symbols of the same name twice, mypy would check to see if that symbol was a variable definition or a function and would allow the import if that symbol was previously imported.

This commit extends this check slightly by also allowing identical classes to be imported twice.

This commit fixes python#2135.

Previously, if you attempted importing two symbols of the same name
twice, mypy would check to see if that symbol was a variable definition
or a function and would allow the import if that symbol was previously
imported.

This commit extends this check slightly by also allowing identical
classes to be imported twice.
@Michael0x2a Michael0x2a changed the title Allow identical classes to be repeated twice Allow identical classes to be imported twice Sep 15, 2016
@gvanrossum
Copy link
Member

Interesting. I'll merge this in a sec, but I am not really comfortable with the (existing!) behavior that overlapping imports are allowed when they import different things that happen to have the same type. The exception is meant for conditional imports, e.g.

if ...:
    from x import a
else:
    from y import a

but it seems it also allows plain overrides:

from x import a
from y import a

where x.a and y.a are unrelated but happen to have the same type.

But that's not this PR's fault, and it looks like colliding classes are always considered to be different, so we're actually better off for classes than for functions!

@gvanrossum gvanrossum merged commit a2d6638 into python:master Sep 15, 2016
@Michael0x2a Michael0x2a deleted the allow-identical-class-imported-twice branch September 16, 2016 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of star-imports nearly always yields "name already defined" errors
2 participants