Skip to content

Commit

Permalink
Merge pull request #128 from leonhard-s/typed-details
Browse files Browse the repository at this point in the history
Add TypedDict versions of _Details type hint
  • Loading branch information
bgreen-litl authored Jul 25, 2021
2 parents bc33cbb + e0cd03e commit 8d9ac3a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
29 changes: 26 additions & 3 deletions backoff/_typing.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
# coding:utf-8
import logging
from typing import Any, Callable, Dict, Generator, Sequence, Union, TypeVar

import sys
from typing import (Any, Callable, Dict, Generator, Sequence, Tuple, Union,
TypeVar)

T = TypeVar("T")

if sys.version_info >= (3, 8):
from typing import TypedDict
else:
try:
from typing_extensions import TypedDict
except ImportError:
TypedDict = object


class _Details(TypedDict):
target: Callable[..., Any]
args: Tuple[Any, ...]
kwargs: Dict[str, Any]
tries: int
elapsed: float


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


_CallableT = TypeVar('_CallableT', bound=Callable[..., Any])
_Handler = Callable[[Dict[str, Any]], None]
_Handler = Callable[[Details], None]
_Jitterer = Callable[[float], float]
_MaybeCallable = Union[T, Callable[[], T]]
_MaybeLogger = Union[str, logging.Logger]
Expand Down
6 changes: 6 additions & 0 deletions backoff/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# coding:utf-8
from ._typing import Details

__all__ = [
'Details'
]

0 comments on commit 8d9ac3a

Please sign in to comment.