get first enum automatically, but ofc mypy doesn't pick up the new metaclass so can't use :(

would have been `CarParams.NetworkLocation()`
This commit is contained in:
Shane Smiskol 2024-08-09 15:51:02 -07:00
parent e52fae0657
commit bb28b228be
1 changed files with 9 additions and 1 deletions

View File

@ -28,7 +28,15 @@ def apply_auto_fields(cls=None, /, **kwargs):
return cls
class StrEnum(_StrEnum):
class EnumMeta(EnumType):
def __call__(cls, value=None, **kwargs):
# Return first enum if value is None
if value is None:
value = next(iter(cls))
return super().__call__(value, **kwargs)
class StrEnum(_StrEnum, metaclass=EnumMeta):
@staticmethod
def _generate_next_value_(name, *args):
# auto() defaults to name.lower()