我有一个函数返回另一个函数,但返回函数的返回类型不清楚。为了表达我们可以使用的函数返回类型Callable[[], ReturnType],并且不强调参数,我们可以这样做Callable[..., ReturnType]。但我希望这ReturnType不是确定的。
我该怎么办?
我的代码是这样的:
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
Run Code Online (Sandbox Code Playgroud)