I have a function which returns another function, but the return type of returned function is not clear. To express function return type we can use Callable[[], ReturnType], and to not emphasize on arguments we can do this Callable[..., ReturnType]. But I want this ReturnType to not be determined.
What should I do?
My code is something like this:
def funcA() -> int:
return 2
def funcB() -> str:
return 'b'
def f(inp: int) -> Callable[[], X] # <--- what should X be Here?
return funcA if inp == 0 else funcB
In theory, f returns either int or str, so the return type should be typing.Union[int, str].
If you don't want to specify the return type then you can use typing.Any.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With