From b556a8213976e012ba2f8c0540743aab9565c946 Mon Sep 17 00:00:00 2001 From: Olivier Delalleau <507137+odelalleau@users.noreply.github.com> Date: Thu, 4 Mar 2021 22:18:39 -0500 Subject: [PATCH] Typing update --- omegaconf/dictconfig.py | 4 +--- omegaconf/nodes.py | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/omegaconf/dictconfig.py b/omegaconf/dictconfig.py index fdebf1865..d5789c17d 100644 --- a/omegaconf/dictconfig.py +++ b/omegaconf/dictconfig.py @@ -292,9 +292,7 @@ def _s_validate_and_normalize_key(self, key_type: Any, key: Any) -> DictKeyType: return key # type: ignore elif issubclass(key_type, Enum): try: - ret = EnumNode.validate_and_convert_to_enum(key_type, key) - assert ret is not None - return ret + return EnumNode.validate_and_convert_to_enum(key_type, key) except ValidationError: valid = ", ".join([x for x in key_type.__members__.keys()]) raise KeyValidationError( diff --git a/omegaconf/nodes.py b/omegaconf/nodes.py index c94ad2c6f..f6300580d 100644 --- a/omegaconf/nodes.py +++ b/omegaconf/nodes.py @@ -337,13 +337,11 @@ def __init__( ), ) - def _validate_and_convert_impl(self, value: Any) -> Optional[Enum]: + def _validate_and_convert_impl(self, value: Any) -> Enum: return self.validate_and_convert_to_enum(enum_type=self.enum_type, value=value) @staticmethod - def validate_and_convert_to_enum( - enum_type: Type[Enum], value: Any - ) -> Optional[Enum]: + def validate_and_convert_to_enum(enum_type: Type[Enum], value: Any) -> Enum: if not isinstance(value, (str, int)) and not isinstance(value, enum_type): raise ValidationError( f"Value $VALUE ($VALUE_TYPE) is not a valid input for {enum_type}"