Use fully qualified names for ambiguous class names resembling builtins.#8425
Use fully qualified names for ambiguous class names resembling builtins.#8425msullivan merged 5 commits intopython:masterfrom
Conversation
Probably we should get them from the stubs for the appropriate Python version mypy is targeting, but I don't know off hand how to do that. |
msullivan
left a comment
There was a problem hiding this comment.
This seems to break a bunch of existing cases.
To figure out what names to worry about, I'd just use the list from TYPES_FOR_UNIMPORTED_HINTS in semanal.py (which can be moved out of it).
Please also make sure to add tests.
Thanks!
|
@msullivan Thanks for the suggestions! I've updated some older outputs that needed changing, I'll try and add a couple of new test cases too.
@JelleZijlstra Thank you! I don't know how to load version-specific stubs though, could you tell me where to start looking? |
Oh, sorry, I overlooked this. I'll look for the names there, thanks! |
|
I've added a test case, but I think I might've added it to the wrong place. Does it belong somewhere else? |
mypy/messages.py
Outdated
| for inst in collect_all_instances(type): | ||
| d.setdefault(inst.type.name, set()).add(inst.type.fullname) | ||
| for shortname in d.keys(): | ||
| if shortname in builtin_types: |
There was a problem hiding this comment.
I would drop the builtins_types part of this
|
Test is in the right place! |
|
I've removed the overlap-check for builtins. Is there a better way to do the check? I guess dir(builtins) is hacky and could cause incorrect messages if the target python version is very different. Thanks for the help! |
| class Any: pass | ||
|
|
||
| x = Any() | ||
| x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "__main__.Any") |
There was a problem hiding this comment.
It would be good to test a few other type names as well, such as list / List. (Lower-case list might not work, since it's not in the TYPES_FOR_UNIMPORTED_HINTS set.)
There was a problem hiding this comment.
I've added a few more types from TYPES_FOR_UNIMPORTED_HINTS.
Resolves #8372.
Is there a better way to get the types from
typingandbuiltins?