I have two functions that are quite similar, the second one calles the first one (and in the actual code does something else afterwards).
Both take two arguments that can take multiple types, bot only certain combinations make sense, therefore I use overload to indicate that (the actual code will also raise for invalid combinations). See the following example:
from typing import overload
@overload
def x(k: int, m: float) -> int:
...
@overload
def x(k: str, m: bytes) -> str:
...
def x(k: int | str, m: float | bytes) -> int | str:
return k
@overload
def y(k: int, m: float) -> int:
...
@overload
def y(k: str, m: bytes) -> str:
...
def y(k: int | str, m: float | bytes) -> int | str:
return x(k, m)
Now mypy complains that:
error: No overload variant of "x" matches argument type "Union[int, str]" [call-overload]
note: Possible overload variants:
note: def x(k: int, m: float) -> int
note: def x(k: str, m: bytes) -> str
What would be the correct way to type such a problem?