]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Fix bug in optional_enum_transformer()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 26 Mar 2024 09:34:07 +0000 (10:34 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 26 Mar 2024 10:12:20 +0000 (11:12 +0100)
We need to instantiate the nested type, not the optional itself.

mkosi/config.py

index c008084b6885039000e4e072ba85f68a8c6a740f..588058d575180081aea84f06b0175e96f1b5fdfa 100644 (file)
@@ -24,6 +24,7 @@ import subprocess
 import sys
 import tempfile
 import textwrap
+import typing
 import uuid
 from collections.abc import Collection, Iterable, Iterator, Sequence
 from pathlib import Path
@@ -3901,7 +3902,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 fieldtype(enumval) if enumval is not None else None  # type: ignore
+        return typing.get_args(fieldtype)[0] 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