Skip to content

Commit

Permalink
style(enums): fix linter issues (#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Oct 5, 2024
1 parent 15c67c0 commit 6300df6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions openfisca_core/indexed_enums/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import numpy

ENUM_ARRAY_DTYPE = numpy.int16


__all__ = ["ENUM_ARRAY_DTYPE"]
4 changes: 3 additions & 1 deletion openfisca_core/indexed_enums/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(self, *__args: object, **__kwargs: object) -> None:
``_member_names_`` is undocumented in upstream :class:`enum.Enum`.
"""

self.index = len(self._member_names_)

#: Bypass the slow :meth:`enum.Enum.__eq__` method.
Expand Down Expand Up @@ -100,3 +99,6 @@ def encode(
).astype(ENUM_ARRAY_DTYPE)

return EnumArray(array, cls)


__all__ = ["Enum"]
12 changes: 6 additions & 6 deletions openfisca_core/indexed_enums/enum_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ def __eq__(self, other: object) -> bool:
https://en.wikipedia.org/wiki/Liskov_substitution_principle
"""

if other.__class__.__name__ is self.possible_values.__name__:
return self.view(numpy.ndarray) == other.index

return self.view(numpy.ndarray) == other

def __ne__(self, other: object) -> bool:
"""Inequality
"""Inequality.
Args:
other: Another :class:`object` to compare to.
Expand All @@ -89,10 +88,10 @@ def __ne__(self, other: object) -> bool:
https://en.wikipedia.org/wiki/Liskov_substitution_principle
"""

return numpy.logical_not(self == other)

def _forbidden_operation(self, other: Any) -> NoReturn:
@staticmethod
def _forbidden_operation(other: Any) -> NoReturn:
msg = (
"Forbidden operation. The only operations allowed on EnumArrays "
"are '==' and '!='."
Expand Down Expand Up @@ -127,7 +126,6 @@ def decode(self) -> numpy.object_:
Decoded value: enum item
"""

return numpy.select(
[self == item.index for item in self.possible_values],
list(self.possible_values),
Expand All @@ -148,7 +146,6 @@ def decode_to_str(self) -> numpy.str_:
'free_lodger' # String identifier
"""

return numpy.select(
[self == item.index for item in self.possible_values],
[item.name for item in self.possible_values],
Expand All @@ -159,3 +156,6 @@ def __repr__(self) -> str:

def __str__(self) -> str:
return str(self.decode_to_str())


__all__ = ["EnumArray"]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"pylint >=3.3.1, <4.0",
"pylint-per-file-ignores >=1.3.2, <2.0",
"pyright >=1.1.382, <2.0",
"ruff >=0.6.7, <1.0",
"ruff >=0.6.9, <1.0",
"ruff-lsp >=0.0.57, <1.0",
"xdoctest >=1.2.0, <2.0",
*api_requirements,
Expand Down
1 change: 1 addition & 0 deletions stubs/numexpr/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import numpy

def evaluate(
__ex: str,
/,
*__args: object,
**__kwargs: object,
) -> NDArray[numpy.bool_] | NDArray[numpy.int32] | NDArray[numpy.float32]: ...

0 comments on commit 6300df6

Please sign in to comment.