我有一个函数,它只能返回类型为 T 的
目前,我使用以下代码:
a
、b
或 c
。由于这些值在函数的上下文中具有特殊意义,因此我希望在函数签名中包含这个信息。如何做到这一点?目前,我使用以下代码:
def fun(...) -> "a or b or c":
#briefly explain the meaning of a, b and c in its docstring
这是正确的吗?
我知道我可以做到这个。
def fun(...) -> T:
# briefly explain the meaning of a, b and c in its docstring
但是正如我所说,我希望在签名中表达这个函数仅返回那些特定的值。