From: Daan De Meyer Date: Sun, 5 May 2024 21:17:20 +0000 (+0200) Subject: Fix optional enum deserialization X-Git-Tag: v23.1~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40ff62d7e20b6798a69d8547f93241960b37d7dc;p=thirdparty%2Fmkosi.git Fix optional enum deserialization --- diff --git a/mkosi/config.py b/mkosi/config.py index a9cdbf907..cb15343da 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -4142,7 +4142,7 @@ def json_type_transformer(refcls: Union[type[Args], type[Config]]) -> Callable[[ return fieldtype(enumval) def optional_enum_transformer(enumval: Optional[str], fieldtype: type[Optional[E]]) -> Optional[E]: - return typing.get_args(fieldtype)[0] if enumval is not None else None + return typing.get_args(fieldtype)[0](enumval) if enumval is not None else None def enum_list_transformer(enumlist: list[str], fieldtype: type[list[E]]) -> list[E]: enumtype = fieldtype.__args__[0] # type: ignore diff --git a/tests/test_json.py b/tests/test_json.py index a759ecf0b..3008bc771 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -317,7 +317,7 @@ def test_config() -> None: "Timezone": null, "ToolsTree": null, "ToolsTreeCertificates": true, - "ToolsTreeDistribution": null, + "ToolsTreeDistribution": "fedora", "ToolsTreeMirror": null, "ToolsTreePackageManagerTrees": [ { @@ -484,7 +484,7 @@ def test_config() -> None: timezone=None, tools_tree=None, tools_tree_certificates=True, - tools_tree_distribution=None, + tools_tree_distribution=Distribution.fedora, tools_tree_mirror=None, tools_tree_package_manager_trees=[ConfigTree(Path("/a/b/c"), Path("/"))], tools_tree_packages=[],