I'm trying to understand how to use the overload decorator when typing functions. If I write the following code and run it through mypy:
from typing import Union, overload
@overload
def myfunc(a: float, b: float) -> float: ...
@overload
def myfunc(a: int, b: int) -> int: ...
def myfunc(a: Union[float, int], b: Union[float, int]) -> Union[float, int]:
return a + b
Then I get a "error: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader Found 1 error in 1 file (checked 1 source file)"
I don't understand why the parameter types of signature 1 (ie. floats) are broader that signature 2 (ie. ints).
What is going on here?