Skip to content
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

Dict, List and Set are imported by default #999

Closed
gvanrossum opened this issue Nov 25, 2015 · 5 comments · Fixed by #2863
Closed

Dict, List and Set are imported by default #999

gvanrossum opened this issue Nov 25, 2015 · 5 comments · Fixed by #2863
Labels
bug mypy got something wrong priority-0-high

Comments

@gvanrossum
Copy link
Member

This code (no import from typing) complains, as expected:

a = None  # type: Any

However, this code passes:

a = None  # type: Dict

Similar with List, Set.

@JukkaL JukkaL added the bug mypy got something wrong label Nov 25, 2015
@JukkaL
Copy link
Collaborator

JukkaL commented Nov 25, 2015

Ah, seems like a problem with how mypy handles generic type aliases, such as Dict -> dict. Not sure exactly why this happens, but my guess is that they leak from builtins.pyi somehow.

@gvanrossum
Copy link
Member Author

FWIW the same thing happens to Set. I don't believe there are other types that have this issue; those three (List, Dict, Set) are treated special by mypy. See https://github.com/python/mypy/blob/master/mypy/nodes.py#L74

@ddfisher ddfisher added this to the 0.3.2 milestone Mar 2, 2016
@gvanrossum gvanrossum changed the title Dict and List seem to be assumed by default Dict, List and Set are imported by default Mar 15, 2016
@gvanrossum
Copy link
Member Author

This is a bit thorny to fix, because Dict/List/Set are currently implemented as aliases to dict/list/set, and all the genericity is specified in typeshed/*/builtins.pyi.

I propose not to worry too much about it for 0.3.2.

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 14, 2016

Agreed. Maybe move this to 0.3.3?

@gvanrossum gvanrossum modified the milestones: 0.3.3, 0.3.2 Apr 14, 2016
@gvanrossum
Copy link
Member Author

Moved to 0.3.3.

gvanrossum pushed a commit that referenced this issue Feb 14, 2017
Fix #999

This is a straightforward fix: List, Set, and Dict are treated as aliases to their builtins counterparts, therefore they are ignored by remove_imported_names_from_symtable, I fix this by also removing the alias names.

The fix also revealed few places in mypy where imports were missing, and one bug in fastparse.py. Those have been fixed.

The fix also includes a typeshed sync at  python/typeshed#933.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-0-high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants