retype
retype copied to clipboard
Support overloaded definitions.
It seems like at this point retype doesn't support overloaded
annotations. Tested with example annotation (foo.pyi
):
from typing import overload
@overload
def f(x: str) -> str: ...
@overload
def f(x: int) -> int: ...
and source file (foo.py
)
def f(x):
if isinstance(x, (str, int)):
return x
else:
raise TypeError(f"x should be str or int, got {type(x)}")
Executing retype
results in
error: /path/to/foo.py: Annotation problem in function 'f': 1:1: incompatible existing annotation for {arg.arg!r}. Expected: 'int', actual: 'str'
Expected output would be
from typing import overload
@overload
def f(x: str) -> str: ...
@overload
def f(x: int) -> int: ...
def f(x):
if isinstance(x, (str, int)):
return x
else:
raise TypeError(f"x should be str or int, got {type(x)}")
or equivalent.