Multiple signatures for functions

Is there a way to create multiple signatures for functions (with working type hints)?

For example, when you type range(), PyCharm suggests you two signatures: `self.range, stop: int` and `self.range, start: int, stop: int, step: int=...`. Other built-ins also have such multiple signatures. Multiple signatures creation possible with typing.overload decorator, but this case doesn't suit me, because I want to write a realization in the place where the function is declared. I need it to make realization of multimethods in python (existing implementations don't cover my needs) with working type hints. For example:

def overload(f): ...  # my overload realization


@overload
def a(b: int):
# realization for case when type(b) == int
pass


@overload
def a(b: str):
# realization for case when type(b) == str
pass


# I want to get next type hints from PyCharm when I type "b()":
# b: int
# b: str
# But I get
# b: str

Please sign in to leave a comment.