diff --git a/openfisca_core/indexed_enums/config.py b/openfisca_core/indexed_enums/config.py index f7da69b84..abb8817de 100644 --- a/openfisca_core/indexed_enums/config.py +++ b/openfisca_core/indexed_enums/config.py @@ -1,3 +1,6 @@ import numpy ENUM_ARRAY_DTYPE = numpy.int16 + + +__all__ = ["ENUM_ARRAY_DTYPE"] diff --git a/openfisca_core/indexed_enums/enum.py b/openfisca_core/indexed_enums/enum.py index a67cd317c..56f007941 100644 --- a/openfisca_core/indexed_enums/enum.py +++ b/openfisca_core/indexed_enums/enum.py @@ -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. @@ -100,3 +99,6 @@ def encode( ).astype(ENUM_ARRAY_DTYPE) return EnumArray(array, cls) + + +__all__ = ["Enum"] diff --git a/openfisca_core/indexed_enums/enum_array.py b/openfisca_core/indexed_enums/enum_array.py index a04e28cdb..b40ba0401 100644 --- a/openfisca_core/indexed_enums/enum_array.py +++ b/openfisca_core/indexed_enums/enum_array.py @@ -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. @@ -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 '!='." @@ -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), @@ -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], @@ -159,3 +156,6 @@ def __repr__(self) -> str: def __str__(self) -> str: return str(self.decode_to_str()) + + +__all__ = ["EnumArray"] diff --git a/setup.py b/setup.py index 202e5e449..d342bb9f4 100644 --- a/setup.py +++ b/setup.py @@ -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, diff --git a/stubs/numexpr/__init__.pyi b/stubs/numexpr/__init__.pyi index f9ada73c3..931d47ddb 100644 --- a/stubs/numexpr/__init__.pyi +++ b/stubs/numexpr/__init__.pyi @@ -4,6 +4,7 @@ import numpy def evaluate( __ex: str, + /, *__args: object, **__kwargs: object, ) -> NDArray[numpy.bool_] | NDArray[numpy.int32] | NDArray[numpy.float32]: ...