Skip to content

Commit 1e88559

Browse files
author
Mauko Quiroga
committed
Rename encodable protocol
1 parent 5be77d1 commit 1e88559

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

openfisca_core/indexed_enums/enum.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
import numpy
77

8-
from openfisca_core.types import ArrayType, Encodable
8+
from openfisca_core.types import ArrayType, SupportsEncode
99

1010
from .. import indexed_enums as enums
1111
from .enum_array import EnumArray
1212

1313
A = Union[
1414
EnumArray,
15-
ArrayType[Encodable],
15+
ArrayType[SupportsEncode],
1616
ArrayType[bytes],
1717
ArrayType[int],
1818
ArrayType[str],
@@ -133,6 +133,18 @@ def __repr__(self) -> str:
133133
def __str__(self) -> str:
134134
return f"{self.__class__.__name__}.{self.name}"
135135

136+
def __eq__(self, other: object) -> bool:
137+
if not isinstance(other, Enum):
138+
return NotImplemented
139+
140+
return self.index == other.index
141+
142+
def __ne__(self, other: object) -> bool:
143+
if not isinstance(other, Enum):
144+
return NotImplemented
145+
146+
return self.index != other.index
147+
136148
def __lt__(self, other: object) -> bool:
137149
if not isinstance(other, Enum):
138150
return NotImplemented
@@ -157,9 +169,6 @@ def __ge__(self, other: object) -> bool:
157169

158170
return self.index >= other.index
159171

160-
__eq__ = object.__eq__
161-
"""Bypass the slow :meth:`~enum.Enum.__eq__`."""
162-
163172
__hash__ = object.__hash__
164173
""":meth:`.__hash__` must also be defined as so to stay hashable."""
165174

openfisca_core/indexed_enums/enum_array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy
66

7-
from openfisca_core.types import ArrayLike, ArrayType, Encodable
7+
from openfisca_core.types import ArrayLike, ArrayType, SupportsEncode
88

99

1010
class EnumArray(numpy.ndarray):
@@ -72,7 +72,7 @@ class EnumArray(numpy.ndarray):
7272
def __new__(
7373
cls,
7474
input_array: ArrayType[int],
75-
possible_values: Optional[Type[Encodable]] = None,
75+
possible_values: Optional[Type[SupportsEncode]] = None,
7676
) -> EnumArray:
7777
"""See comment above."""
7878

@@ -195,7 +195,7 @@ def _forbidden_operation(self, other: Any) -> NoReturn:
195195
__and__ = _forbidden_operation
196196
__or__ = _forbidden_operation
197197

198-
def decode(self) -> ArrayLike[Encodable]:
198+
def decode(self) -> ArrayLike[SupportsEncode]:
199199
"""Decodes itself to a normal array.
200200
201201
Returns:

0 commit comments

Comments
 (0)