pyre-check
pyre-check copied to clipboard
False positive when combining literals and overloads
Given the following code, pyre outputs an error that the first overload signature is not valid for the given implementation, which I believe is incorrect.
from typing import overload
from typing_extensions import Literal
@overload
def func(*, the_bool: Literal[True]) -> None: # Incompatible overload [43]:
# The implementation of `func` does not accept all possible arguments of
# overload defined on line X
...
@overload
def func(the_bool: Literal[False] = False) -> None:
...
@overload
def func(the_bool: bool = False) -> None:
...
def func(the_bool: bool = False) -> None:
print(the_bool)
My original use-case for this is that the value of the boolean controls the kind of the return type (which is explicit on the first two overloads and a Union on the third and the implementation), but that wasn't needed to reproduce the issue.
I believe that this is a false positive error because the actual implementation will accept the_bool as a kwarg, which is what the first overload requires.
Hi @PeterJCLaw,
If you remove the * parameter in the first overload, this works properly. We don't handle correctly * parameters in overloads, this is a known issue.
@arthaud thanks for the response.
Unfortunately my original use-case has other arguments such that removing the * changes the overload to no longer be valid for the actual implementation.
If you've got another task for * in overloads feel free to close this as a duplicate though.