From b68cf7a7e50a55f2e2e28680f3cad5fbca8497d6 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 27 Nov 2024 09:56:41 +0100 Subject: [PATCH] API/serde: fix construction of Enum values --- pkgs/clan-cli/clan_cli/api/serde.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/clan-cli/clan_cli/api/serde.py b/pkgs/clan-cli/clan_cli/api/serde.py index 394f077e2..84328186b 100644 --- a/pkgs/clan-cli/clan_cli/api/serde.py +++ b/pkgs/clan-cli/clan_cli/api/serde.py @@ -230,10 +230,18 @@ def construct_value( raise ClanError(msg, location=f"{loc}") return field_value + # Enums if origin is Enum: if field_value not in origin.__members__: msg = f"Expected one of {', '.join(origin.__members__)}, got {field_value}" 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: (base_type,) = get_args(t)