@overload outside stubs
PEP 484 says that @overload is only allowed in stubs.
But if I have a function like this:
def plus1(x): return x + 1
then the most precise type is an overload:
def plus1(x: int) -> int
def plus1(x: float) -> float
def plus1(x: complex) -> complex
This particular case could, of course, be handled by
Number = TypeVar('Number', int, float, complex) def f(x: Number) -> Number
But I can easily construct other examples that can't be solved by type variables.
I don't think that @overload requires any additional dispatch machinery in Python (despite what the PEP says) -- it merely describes what the function can do in a more precise way than this:
def plus1(x: Union[int,float,complex]) -> Union[int,float,complex]