Suppose the following code:
from typing import Union
def invert(value: Union[str, int]) -> Union[int, str]:
if isinstance(value, str):
return int(value)
elif isinstance(value, int):
return str(value)
else:
raise ValueError("value must be 'int' or 'str'")
It is easily seen that a str
input leads to an int
output and vice versa. Is there a way to specify the return type so that it encodes this inverse relationship?