]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Fix optional enum deserialization
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 5 May 2024 21:17:20 +0000 (23:17 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 5 May 2024 21:19:44 +0000 (23:19 +0200)
mkosi/config.py
tests/test_json.py

index a9cdbf907254028442e34d643e49e3201819dc08..cb15343daa98312ca83f365ad47c141f2901920f 100644 (file)
@@ -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
index a759ecf0b7ef8201ac5bfc18eea447853e801606..3008bc7715919f6575ff14c5e74dffa17a1bde96 100644 (file)
@@ -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=[],