diff --git a/rithm/_enums.py b/rithm/_enums.py index 22d4db6..2b595e0 100644 --- a/rithm/_enums.py +++ b/rithm/_enums.py @@ -25,9 +25,10 @@ def __init_subclass__(cls, /, **_kwargs: Any) -> NoReturn: ) def __new__(cls, value: int, /) -> Self: - if not isinstance(value, int): - raise TypeError(type(value)) - if not (0 <= value < len(get_type_hints(cls, globals()))): + if not ( + isinstance(value, int) + and 0 <= value < len(get_type_hints(cls, globals())) + ): raise ValueError(f'{value} is not a valid {cls.__qualname__}') try: return cls._cache[value] @@ -37,6 +38,9 @@ def __new__(cls, value: int, /) -> Self: cls._cache[value] = self return self + def __getnewargs__(self) -> tuple[int]: + return (self._value,) + def __repr__(self) -> str: name = next( name for name, field in vars(type(self)).items() if field is self @@ -70,9 +74,10 @@ def __init_subclass__(cls, /, **_kwargs: Any) -> NoReturn: ) def __new__(cls, value: int, /) -> Self: - if not isinstance(value, int): - raise TypeError(type(value)) - if not (0 <= value < len(get_type_hints(cls, globals()))): + if not ( + isinstance(value, int) + and 0 <= value < len(get_type_hints(cls, globals())) + ): raise ValueError(f'{value} is not a valid {cls.__qualname__}') try: return cls._cache[value] @@ -82,6 +87,9 @@ def __new__(cls, value: int, /) -> Self: cls._cache[value] = self return self + def __getnewargs__(self) -> tuple[int]: + return (self._value,) + def __repr__(self) -> str: name = next( name for name, field in vars(type(self)).items() if field is self