API/serde: fix construction of Enum values
This commit is contained in:
@@ -230,10 +230,18 @@ def construct_value(
|
|||||||
raise ClanError(msg, location=f"{loc}")
|
raise ClanError(msg, location=f"{loc}")
|
||||||
return field_value
|
return field_value
|
||||||
|
|
||||||
|
# Enums
|
||||||
if origin is Enum:
|
if origin is Enum:
|
||||||
if field_value not in origin.__members__:
|
if field_value not in origin.__members__:
|
||||||
msg = f"Expected one of {', '.join(origin.__members__)}, got {field_value}"
|
msg = f"Expected one of {', '.join(origin.__members__)}, got {field_value}"
|
||||||
raise ClanError(msg, location=f"{loc}")
|
raise ClanError(msg, location=f"{loc}")
|
||||||
|
return origin.__members__[field_value] # type: ignore
|
||||||
|
|
||||||
|
if isinstance(t, type) and issubclass(t, Enum):
|
||||||
|
if field_value not in t.__members__:
|
||||||
|
msg = f"Expected one of {', '.join(t.__members__)}, got {field_value}"
|
||||||
|
raise ClanError(msg, location=f"{loc}")
|
||||||
|
return t.__members__[field_value] # type: ignore
|
||||||
|
|
||||||
if origin is Annotated:
|
if origin is Annotated:
|
||||||
(base_type,) = get_args(t)
|
(base_type,) = get_args(t)
|
||||||
|
|||||||
Reference in New Issue
Block a user