我有这段代码:
import enum
class Color(enum.Enum):
RED = '1'
BLUE = '2'
GREEN = '3'
def get_color_return_something(some_color):
pass
Run Code Online (Sandbox Code Playgroud)
some_color如果我想从Color枚举中接收值(例如:),如何在此函数中的变量中正确添加类型注释Color.RED?
我有一个只能返回的函数a,b或者c它们都属于类型,T但是我想将它的一部分签名这个事实,因为它们在函数的上下文中具有特殊含义,我是如何做到的?
目前我用这个
def fun(...) -> "a or b or c":
#briefly explain the meaning of a, b and c in its docstring
Run Code Online (Sandbox Code Playgroud)
那是正确的吗?
我知道我可以做到这一点
def fun(...) -> T:
#briefly explain the meaning of a, b and c in its docstring
Run Code Online (Sandbox Code Playgroud)
但正如我所说,我想在签名中表达该函数只返回那些特定的值