Skip to content

Commit

Permalink
Typing update
Browse files Browse the repository at this point in the history
  • Loading branch information
odelalleau committed Mar 5, 2021
1 parent fc1d2c3 commit b556a82
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 1 addition & 3 deletions omegaconf/dictconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions omegaconf/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit b556a82

Please sign in to comment.