Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backoff/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def _prepare_logger(logger):
# Configure handler list with user specified handler and optionally
# with a default handler bound to the specified logger.
def _config_handlers(
user_handlers, *, default_handler=None, logger=None, log_level=None
user_handlers, *, default_handler=None, logger=None, log_level=None,
):
handlers = []
if logger is not None:
assert log_level is not None, "Log level is not specified"
# bind the specified logger to the default log handler
log_handler = functools.partial(
default_handler, logger=logger, log_level=log_level
default_handler, logger=logger, log_level=log_level,
)
handlers.append(log_handler)

Expand Down
10 changes: 5 additions & 5 deletions backoff/_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
_prepare_logger,
_config_handlers,
_log_backoff,
_log_giveup
_log_giveup,
)
from backoff._jitter import full_jitter
from backoff import _async, _sync
Expand Down Expand Up @@ -89,13 +89,13 @@ def decorate(target):
on_backoff,
default_handler=_log_backoff,
logger=logger,
log_level=backoff_log_level
log_level=backoff_log_level,
)
on_giveup = _config_handlers(
on_giveup,
default_handler=_log_giveup,
logger=logger,
log_level=giveup_log_level
log_level=giveup_log_level,
)

if inspect.iscoroutinefunction(target):
Expand All @@ -113,7 +113,7 @@ def decorate(target):
on_success=on_success,
on_backoff=on_backoff,
on_giveup=on_giveup,
wait_gen_kwargs=wait_gen_kwargs
wait_gen_kwargs=wait_gen_kwargs,
)

# Return a function which decorates a target with a retry loop.
Expand Down Expand Up @@ -215,7 +215,7 @@ def decorate(target):
on_backoff=on_backoff,
on_giveup=on_giveup,
raise_on_giveup=raise_on_giveup,
wait_gen_kwargs=wait_gen_kwargs
wait_gen_kwargs=wait_gen_kwargs,
)

# Return a function which decorates a target with a retry loop.
Expand Down
8 changes: 4 additions & 4 deletions backoff/_wait_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def expo(
base: float = 2,
factor: float = 1,
max_value: Optional[float] = None
max_value: Optional[float] = None,
) -> Generator[float, Any, None]:

"""Generator for exponential decay.
Expand All @@ -35,7 +35,7 @@ def expo(
def decay(
initial_value: float = 1,
decay_factor: float = 1,
min_value: Optional[float] = None
min_value: Optional[float] = None,
) -> Generator[float, Any, None]:

"""Generator for exponential decay[1]:
Expand Down Expand Up @@ -83,7 +83,7 @@ def fibo(max_value: Optional[int] = None) -> Generator[int, None, None]:


def constant(
interval: Union[int, Iterable[float]] = 1
interval: Union[int, Iterable[float]] = 1,
) -> Generator[float, None, None]:
"""Generator for constant intervals.

Expand All @@ -104,7 +104,7 @@ def constant(

def runtime(
*,
value: Callable[[Any], float]
value: Callable[[Any], float],
) -> Generator[float, None, None]:
"""Generator that is based on parsing the return value or thrown
exception of the decorated method
Expand Down
2 changes: 1 addition & 1 deletion backoff/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from ._typing import Details

__all__ = [
'Details'
'Details',
]
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ description = "format code"
dependency_groups = [ "lint" ]
commands = [
[ "ruff", "check", "--fix", { replace = "posargs", default = [ "backoff", "tests" ], extend = true } ],
# [ "ruff", "format", { replace = "posargs", default = [ "backoff", "tests" ], extend = true } ],
]

[tool.tox.env.lint]
Expand Down Expand Up @@ -179,6 +180,11 @@ source = [
"backoff",
]

[tool.ruff.lint]
extend-select = [
"COM", # flake8-commas
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
14 changes: 7 additions & 7 deletions tests/test_backoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_on_predicate_max_time(monkeypatch):
10.000005,
9,
1,
0
0,
]

def monotonic():
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_on_predicate_max_time_callable(monkeypatch):
10.000005,
9,
1,
0
0,
]

def monotonic():
Expand Down Expand Up @@ -840,7 +840,7 @@ def key_error():


def _on_exception_factory(
backoff_log_level, giveup_log_level, max_tries
backoff_log_level, giveup_log_level, max_tries,
):
@backoff.on_exception(
backoff.expo,
Expand All @@ -860,7 +860,7 @@ def func():


def _on_predicate_factory(
backoff_log_level, giveup_log_level, max_tries
backoff_log_level, giveup_log_level, max_tries,
):
@backoff.on_predicate(
backoff.expo,
Expand Down Expand Up @@ -889,17 +889,17 @@ def func():
repeat=2,
)
for factory in (_on_predicate_factory, _on_exception_factory)
)
),
)
def test_event_log_levels(
caplog, func_factory, backoff_log_level, giveup_log_level
caplog, func_factory, backoff_log_level, giveup_log_level,
):
max_tries = 3
func = func_factory(backoff_log_level, giveup_log_level, max_tries)

with unittest.mock.patch('time.sleep', return_value=None):
with caplog.at_level(
min(backoff_log_level, giveup_log_level), logger="backoff"
min(backoff_log_level, giveup_log_level), logger="backoff",
):
func()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def foo():
backoff.constant,
ValueError,
interval=1,
max_tries=3
max_tries=3,
)
def bar():
raise ValueError()
Expand Down
Loading