You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong checking of overload for keyword-only args #1907
While writing some stubs I found an issue that I simplified to the following:
fromtypingimportoverload@overloaddeff(*, out: str, flag: bool=False) ->str: ...
@overloaddeff(*, flag: bool=False) ->bool: ...
reveal_type(f()) # I expect bool, get Anyreveal_type(f(flag=False)) # I expect bool, get Anyreveal_type(f(out="xxx")) # I expect str, get str
The checker shows a
error: Overloaded function signatures 1 and 2 overlap with incompatible return types
but actually the signatures do not overlap (there's no call that can match both the signatures).
Something that's also confusing is that if I change the order of the arguments like this
# Move the "out" argument to the end@overloaddeff(*, flag: bool=False, out: str) ->str: ...
@overloaddeff(*, flag: bool=False) ->bool: ...
I stop getting the "signature overlap" error, but I still get the "Any" type on the first two example calls. Given that these arguments are keyword only their positions shouldn't matter at all
This took way way longer to resolve then I originally thought it would take, but the above examples are working as expected now in master after f61c2ba.
There's still a few todos related to handling edge cases w.r.t. star args, optional args, and such in #5163 that needs to land before we can really call this done, but I'm going to close this mostly so I can prune the list of overload-related things I have left to do.
Activity
euresti commentedon Dec 14, 2017
Very weirdly it's the kwonly that's causing issues:
This code has no issues:
But make those kwonly and boom:
Make overloads respect keyword-only args
Make overloads respect keyword-only args
Make overloads respect keyword-only args
Make overloads respect keyword-only args
ilevkivskyi commentedon May 17, 2018
The
Anyreturn is now fixed, but the overlap error still appears, so this is a false positive.Michael0x2a commentedon Jun 15, 2018
This took way way longer to resolve then I originally thought it would take, but the above examples are working as expected now in master after f61c2ba.
There's still a few todos related to handling edge cases w.r.t. star args, optional args, and such in #5163 that needs to land before we can really call this done, but I'm going to close this mostly so I can prune the list of overload-related things I have left to do.