【发布时间】:2021-10-26 22:43:48
【问题描述】:
我有一个函数返回另一个函数,但返回函数的返回类型不清楚。为了表示函数返回类型,我们可以使用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
【问题讨论】:
标签: python type-hinting python-typing