Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward arguments to max_tries and max_time #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions backoff/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def retry_predicate(target, wait_gen, predicate,
async def retry(*args, **kwargs):

# update variables from outer function args
max_tries_value = _maybe_call(max_tries)
max_time_value = _maybe_call(max_time)
max_tries_value = _maybe_call(max_tries, *args, **kwargs)
max_time_value = _maybe_call(max_time, *args, **kwargs)

tries = 0
start = datetime.datetime.now()
Expand Down Expand Up @@ -130,8 +130,8 @@ def retry_exception(target, wait_gen, exception,
@functools.wraps(target)
async def retry(*args, **kwargs):

max_tries_value = _maybe_call(max_tries)
max_time_value = _maybe_call(max_time)
max_tries_value = _maybe_call(max_tries, *args, **kwargs)
max_time_value = _maybe_call(max_time, *args, **kwargs)

tries = 0
start = datetime.datetime.now()
Expand Down
7 changes: 5 additions & 2 deletions backoff/_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding:utf-8

import inspect
import functools
import logging
import sys
Expand All @@ -17,7 +17,10 @@
def _maybe_call(f, *args, **kwargs):
if callable(f):
try:
return f(*args, **kwargs)
if len(inspect.signature(f).parameters) == 0:
f()
else:
return f(*args, **kwargs)
except TypeError:
return f
else:
Expand Down
8 changes: 4 additions & 4 deletions backoff/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def retry_predicate(target, wait_gen, predicate,

@functools.wraps(target)
def retry(*args, **kwargs):
max_tries_value = _maybe_call(max_tries)
max_time_value = _maybe_call(max_time)
max_tries_value = _maybe_call(max_tries, *args, **kwargs)
max_time_value = _maybe_call(max_time, *args, **kwargs)

tries = 0
start = datetime.datetime.now()
Expand Down Expand Up @@ -84,8 +84,8 @@ def retry_exception(target, wait_gen, exception,

@functools.wraps(target)
def retry(*args, **kwargs):
max_tries_value = _maybe_call(max_tries)
max_time_value = _maybe_call(max_time)
max_tries_value = _maybe_call(max_tries, *args, **kwargs)
max_time_value = _maybe_call(max_time, *args, **kwargs)

tries = 0
start = datetime.datetime.now()
Expand Down
2 changes: 1 addition & 1 deletion backoff/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Details(_Details, total=False):
Callable[[Details], Coroutine[Any, Any, None]],
]
_Jitterer = Callable[[float], float]
_MaybeCallable = Union[T, Callable[[], T]]
_MaybeCallable = Union[T, Callable[..., T]]
_MaybeLogger = Union[str, logging.Logger, None]
_MaybeSequence = Union[T, Sequence[T]]
_Predicate = Callable[[T], bool]
Expand Down