Skip to main content

maybe_as_enum

No overview available.

def maybe_as_enum(
value: Any,
enum_type: Type[Enum]
) - > Any

Converts a raw value into a member of a specified Enum class if possible, otherwise returns the original value.

Parameters

NameTypeDescription
valueAnyThe raw input value to be converted, typically a string or integer representing an enum member.
enum_typeType[Enum]The Enum class against which the input value is validated and converted.

Returns

TypeDescription
AnyThe corresponding Enum member if the value is valid for the Enum type, otherwise the original input value.