-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix overload handling with union types in signatures #3300
Conversation
Previously `None` was not considered as more precise than `Optional[x]`, which was obviously incorrect. Fixed the implementation of type precision checking to match the description, how that proper subtype checking works. Fixes the original example in #3295.
mypy/subtypes.py
Outdated
@@ -720,4 +720,4 @@ def is_more_precise(t: Type, s: Type) -> bool: | |||
# Fall back to subclass check and ignore other properties of the callable. | |||
return is_proper_subtype(t.fallback, s) | |||
return is_proper_subtype(t, s) | |||
return sametypes.is_same_type(t, s) | |||
return is_proper_subtype(t, s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a special case when t
is CallableType
and s
is Instance
? It looks like ProperSubtypeVisitor
above does exactly the same. So that the whole function boils down to:
if isinstance(s, AnyType):
return True
return is_proper_subtype(t, s)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I puzzled over this for a while and it really doesn't help that the visitor uses left/right while this function uses t/s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
I had a similar testcase based on #3295 which still gives an error:
With
|
@JukkaL This seems stalled waiting for action/response on your end. |
@JukkaL, ping? |
This PR only addresses the first example in #3295. The more general issue requires a much more involved fix, and I think that it can be fixed in a separate PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for me as a quick fix. A broader solution for #3295 can be in a separate PR
Don't merge yet -- I'll check this with Dropbox internal codebases first. |
This doesn't work quite right when run against Dropbox internal codebases. I won't merge this until I've resolved the issue. |
Previously
None
was not considered as more precise thanOptional[x]
, which was obviously incorrect. Fixed theimplementation of type precision checking to match the
description, now that proper subtype checking works.
Fixes the original example in #3295.