26 """Abstract base class for retry strategies."""
29 def __call__(self, retry_state:
"RetryCallState") -> bool:
32 def __and__(self, other:
"retry_base") ->
"retry_all":
35 def __or__(self, other:
"retry_base") ->
"retry_any":
43 """Retry strategy that never rejects any result."""
45 def __call__(self, retry_state:
"RetryCallState") -> bool:
53 """Retry strategy that always rejects any result."""
55 def __call__(self, retry_state:
"RetryCallState") -> bool:
63 """Retry strategy that retries if an exception verifies a predicate."""
65 def __init__(self, predicate: typing.Callable[[BaseException], bool]) ->
None:
68 def __call__(self, retry_state:
"RetryCallState") -> bool:
70 raise RuntimeError(
"__call__() called before outcome was set")
75 raise RuntimeError(
"outcome failed but the exception is None")
82 """Retries if an exception has been raised of one or more types."""
86 exception_types: typing.Union[
96 """Retries except an exception has been raised of one or more types."""
100 exception_types: typing.Union[
110 """Retries until an exception is raised of one or more types."""
114 exception_types: typing.Union[
122 def __call__(self, retry_state:
"RetryCallState") -> bool:
124 raise RuntimeError(
"__call__() called before outcome was set")
131 if exception
is None:
132 raise RuntimeError(
"outcome failed but the exception is None")
137 """Retries if any of the causes of the raised exception is of one or more types.
139 The check on the type of the cause of the exception is done recursively (until finding
140 an exception in the chain that has no `__cause__`)
145 exception_types: typing.Union[
152 def __call__(self, retry_state:
"RetryCallState") -> bool:
154 raise RuntimeError(
"__call__ called before outcome was set")
158 while exc
is not None:
167 """Retries if the result verifies a predicate."""
172 def __call__(self, retry_state:
"RetryCallState") -> bool:
174 raise RuntimeError(
"__call__() called before outcome was set")
183 """Retries if the result refutes a predicate."""
188 def __call__(self, retry_state:
"RetryCallState") -> bool:
190 raise RuntimeError(
"__call__() called before outcome was set")
199 """Retries if an exception message equals or matches."""
203 message: typing.Optional[str] =
None,
206 if message
and match:
207 raise TypeError(f
"{self.__class__.__name__}() takes either 'message' or 'match', not both")
213 return message == str(exception)
215 predicate = message_fnc
219 def match_fnc(exception: BaseException) -> bool:
222 predicate = match_fnc
224 raise TypeError(f
"{self.__class__.__name__}() missing 1 required argument 'message' or 'match'")
230 """Retries until an exception message equals or matches."""
234 message: typing.Optional[str] =
None,
242 def __call__(self, retry_state:
"RetryCallState") -> bool:
244 raise RuntimeError(
"__call__() called before outcome was set")
250 if exception
is None:
251 raise RuntimeError(
"outcome failed but the exception is None")
256 """Retries if any of the retries condition is valid."""
261 def __call__(self, retry_state:
"RetryCallState") -> bool:
266 """Retries if all the retries condition are valid."""
271 def __call__(self, retry_state:
"RetryCallState") -> bool:
272 return all(
r(retry_state)
for r
in self.
retries)
bool __call__(self, "RetryCallState" retry_state)
bool __call__(self, "RetryCallState" retry_state)
bool __call__(self, "RetryCallState" retry_state)
None __init__(self, *retry_base retries)
bool __call__(self, "RetryCallState" retry_state)
None __init__(self, *retry_base retries)
bool __call__(self, "RetryCallState" retry_state)
"retry_all" __and__(self, "retry_base" other)
"retry_any" __or__(self, "retry_base" other)
bool __call__(self, "RetryCallState" retry_state)
None __init__(self, typing.Union[typing.Type[BaseException], typing.Tuple[typing.Type[BaseException],...],] exception_types=Exception)
None __init__(self, typing.Optional[str] message=None, typing.Optional[str] match=None)
None __init__(self, typing.Union[typing.Type[BaseException], typing.Tuple[typing.Type[BaseException],...],] exception_types=Exception)
bool __call__(self, "RetryCallState" retry_state)
None __init__(self, typing.Callable[[BaseException], bool] predicate)
None __init__(self, typing.Optional[str] message=None, typing.Optional[str] match=None)
bool __call__(self, "RetryCallState" retry_state)
None __init__(self, typing.Union[typing.Type[BaseException], typing.Tuple[typing.Type[BaseException],...],] exception_types=Exception)
bool __call__(self, "RetryCallState" retry_state)
None __init__(self, typing.Callable[[typing.Any], bool] predicate)
bool __call__(self, "RetryCallState" retry_state)
None __init__(self, typing.Callable[[typing.Any], bool] predicate)
bool __call__(self, "RetryCallState" retry_state)
None __init__(self, typing.Union[typing.Type[BaseException], typing.Tuple[typing.Type[BaseException],...],] exception_types=Exception)