Skip to content

Commit

Permalink
refactor(commons): fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Sep 20, 2024
1 parent 1414b11 commit bdc65ea
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
20 changes: 12 additions & 8 deletions openfisca_core/commons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,22 @@
"""

# Official Public API

from .dummy import Dummy # noqa: F401
from .formulas import apply_thresholds, concat, switch
from .misc import empty_clone, eval_expression, stringify_array
from .rates import average_rate, marginal_rate

__all__ = ["apply_thresholds", "concat", "switch"]
__all__ = ["empty_clone", "stringify_array", "eval_expression", *__all__]
__all__ = ["average_rate", "marginal_rate", *__all__]

# Deprecated

from .dummy import Dummy # noqa: F401

__all__ = ["Dummy", *__all__]
__all__ = [
"apply_thresholds",
"concat",
"switch",
"empty_clone",
"stringify_array",
"eval_expression",
"average_rate",
"marginal_rate",
"Dummy",
]
3 changes: 3 additions & 0 deletions openfisca_core/commons/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ def __init__(self) -> None:
]
warnings.warn(" ".join(message), DeprecationWarning, stacklevel=2)
pass


__all__ = ["Dummy"]
3 changes: 3 additions & 0 deletions openfisca_core/commons/formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,6 @@ def switch(
condlist = [conditions == condition for condition in value_by_condition.keys()]

return numpy.select(condlist, tuple(value_by_condition.values()))


__all__ = ["apply_thresholds", "concat", "switch"]
15 changes: 5 additions & 10 deletions openfisca_core/commons/misc.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from typing import Optional, TypeVar
from __future__ import annotations

import numexpr

from openfisca_core import types as t

T = TypeVar("T")


def empty_clone(original: T) -> T:
def empty_clone(original: object) -> object:
"""Create an empty instance of the same class of the original object.
Args:
Expand All @@ -31,21 +29,18 @@ def empty_clone(original: T) -> T:
"""

Dummy: object
new: T

Dummy = type(
"Dummy",
(original.__class__,),
{"__init__": lambda self: None},
original.__class__.__bases__,
{"__init__": lambda _: None},
)

new = Dummy()
new.__class__ = original.__class__
return new


def stringify_array(array: Optional[t.Array[t.ArrayAny]]) -> str:
def stringify_array(array: None | t.Array[t.ArrayAny]) -> str:
"""Generate a clean string representation of a numpy array.
Args:
Expand Down
3 changes: 3 additions & 0 deletions openfisca_core/commons/rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,6 @@ def marginal_rate(
)

return marginal_rate


__all__ = ["average_rate", "marginal_rate"]
23 changes: 16 additions & 7 deletions openfisca_core/commons/types.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from openfisca_core.types import ( # noqa: F401
Array as Array,
ArrayAny as ArrayAny,
ArrayBool as ArrayBool,
ArrayFloat as ArrayFloat,
ArrayLike as ArrayLike,
ArrayStr as ArrayStr,
from openfisca_core.types import (
Array,
ArrayAny,
ArrayBool,
ArrayFloat,
ArrayLike,
ArrayStr,
)

__all__ = [
"Array",
"ArrayAny",
"ArrayBool",
"ArrayFloat",
"ArrayLike",
"ArrayStr",
]

0 comments on commit bdc65ea

Please sign in to comment.