Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Module of types used in tubthumper"""
3import sys
4from typing import (
5 Any,
6 Awaitable,
7 Callable,
8 Iterable,
9 Mapping,
10 Optional,
11 Tuple,
12 Type,
13 TypeVar,
14 Union,
15)
17if sys.version_info >= (3, 8):
18 from typing import Protocol
19else:
20 from typing_extensions import Protocol
23Exceptions = Union[Type[Exception], Tuple[Type[Exception]]]
24Args = Optional[Iterable[Any]]
25Kwargs = Optional[Mapping[str, Any]]
26RetryLimit = float
27TimeLimit = float
28InitBackoff = float
29Exponential = float
30Jitter = bool
31Reraise = bool
32LogLevel = int
34T = TypeVar("T")
35RetryCallable = Callable[..., T]
36AwaitableCallable = Callable[..., Awaitable[T]]
37Decorator = Callable[[RetryCallable[T]], RetryCallable[T]]
40class Logger(Protocol):
41 """
42 Generally a `logging.Logger`, but since we want to support
43 `duck-typing <https://docs.python.org/3/glossary.html#term-duck-typing>`_,
44 this is a `typing.Protocol` to enable
45 `structural subtyping <https://www.python.org/dev/peps/pep-0544/>`_.
46 """
48 def log(
49 self, level: int, msg: str, *args: Any, exc_info: bool, **kwargs: Any
50 ) -> Any:
51 r"""We call this method to log at the configured level with ``exc_info=True``
53 Args:
54 level:
55 the level of the message to be logged
56 msg:
57 the message to be logged
58 exc_info:
59 causes exception information to be added to the logging message
60 """