retype icon indicating copy to clipboard operation
retype copied to clipboard

Support overloaded definitions.

Open zero323 opened this issue 4 years ago • 0 comments

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.

zero323 avatar Sep 12 '19 19:09 zero323