edq.util.enum
1import enum 2import typing 3 4def has_value(enum_class: typing.Type[enum.Enum], value: typing.Any) -> bool: 5 """ Check if the given value is one of the possible values for the given enum. """ 6 7 # If the value is already a member of the target class, just check normal membership. 8 if (isinstance(value, enum_class) and (value in enum_class)): 9 return True 10 11 # If the value is from a different enum class, then skip the value check. 12 if (isinstance(value, enum.Enum) and (not isinstance(value, enum_class))): 13 return False 14 15 enum_values = {member.value for member in enum_class} 16 return (value in enum_values)
def
has_value(enum_class: Type[enum.Enum], value: Any) -> bool:
5def has_value(enum_class: typing.Type[enum.Enum], value: typing.Any) -> bool: 6 """ Check if the given value is one of the possible values for the given enum. """ 7 8 # If the value is already a member of the target class, just check normal membership. 9 if (isinstance(value, enum_class) and (value in enum_class)): 10 return True 11 12 # If the value is from a different enum class, then skip the value check. 13 if (isinstance(value, enum.Enum) and (not isinstance(value, enum_class))): 14 return False 15 16 enum_values = {member.value for member in enum_class} 17 return (value in enum_values)
Check if the given value is one of the possible values for the given enum.