Reputation: 404
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
Upvotes: 3
Views: 929
Reputation: 328
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
.
Upvotes: 7