Skip to content

Commit

Permalink
Merge branch 'fix-typing'
Browse files Browse the repository at this point in the history
  • Loading branch information
bgreen-litl committed Oct 5, 2022
2 parents 31d973f + 77f4209 commit 3f491ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
12 changes: 6 additions & 6 deletions backoff/_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def on_predicate(wait_gen: _WaitGenerator,
max_tries: Optional[_MaybeCallable[int]] = None,
max_time: Optional[_MaybeCallable[float]] = None,
jitter: Union[_Jitterer, None] = full_jitter,
on_success: Union[_Handler, Iterable[_Handler]] = None,
on_backoff: Union[_Handler, Iterable[_Handler]] = None,
on_giveup: Union[_Handler, Iterable[_Handler]] = None,
on_success: Union[_Handler, Iterable[_Handler], None] = None,
on_backoff: Union[_Handler, Iterable[_Handler], None] = None,
on_giveup: Union[_Handler, Iterable[_Handler], None] = None,
logger: _MaybeLogger = 'backoff',
backoff_log_level: int = logging.INFO,
giveup_log_level: int = logging.ERROR,
Expand Down Expand Up @@ -127,9 +127,9 @@ def on_exception(wait_gen: _WaitGenerator,
max_time: Optional[_MaybeCallable[float]] = None,
jitter: Union[_Jitterer, None] = full_jitter,
giveup: _Predicate[Exception] = lambda e: False,
on_success: Union[_Handler, Iterable[_Handler]] = None,
on_backoff: Union[_Handler, Iterable[_Handler]] = None,
on_giveup: Union[_Handler, Iterable[_Handler]] = None,
on_success: Union[_Handler, Iterable[_Handler], None] = None,
on_backoff: Union[_Handler, Iterable[_Handler], None] = None,
on_giveup: Union[_Handler, Iterable[_Handler], None] = None,
raise_on_giveup: bool = True,
logger: _MaybeLogger = 'backoff',
backoff_log_level: int = logging.INFO,
Expand Down
19 changes: 10 additions & 9 deletions backoff/_typing.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# coding:utf-8
import logging
import sys
from typing import (Any, Callable, Dict, Generator, Sequence, Tuple, Union,
TypeVar)


details_kwargs = {"total": False}
from typing import (Any, Callable, Coroutine, Dict, Generator, Sequence, Tuple,
TypeVar, Union)

if sys.version_info >= (3, 8): # pragma: no cover
from typing import TypedDict
Expand All @@ -14,8 +11,9 @@
try:
from typing_extensions import TypedDict
except ImportError:
TypedDict = Dict[str, Any]
del details_kwargs["total"]
class TypedDict(dict):
def __init_subclass__(cls, **kwargs: Any) -> None:
return super().__init_subclass__()


class _Details(TypedDict):
Expand All @@ -26,15 +24,18 @@ class _Details(TypedDict):
elapsed: float


class Details(_Details, **details_kwargs):
class Details(_Details, total=False):
wait: float # present in the on_backoff handler case for either decorator
value: Any # present in the on_predicate decorator case


T = TypeVar("T")

_CallableT = TypeVar('_CallableT', bound=Callable[..., Any])
_Handler = Callable[[Details], None]
_Handler = Union[
Callable[[Details], None],
Callable[[Details], Coroutine[Any, Any, None]],
]
_Jitterer = Callable[[float], float]
_MaybeCallable = Union[T, Callable[[], T]]
_MaybeLogger = Union[str, logging.Logger, None]
Expand Down

0 comments on commit 3f491ca

Please sign in to comment.