We need to instantiate the nested type, not the optional itself.
import sys
import tempfile
import textwrap
+import typing
import uuid
from collections.abc import Collection, Iterable, Iterator, Sequence
from pathlib import Path
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