summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-06-09 10:28:54 +0300
committerrobot-piglet <[email protected]>2025-06-09 10:40:32 +0300
commitee361058292c59b05d70833498a72e59c6de0410 (patch)
tree1ddc768402898ea2545750d536c50a5abcb01530
parent6c44ab0f075c82d8eb1453ee8e517b177db2fb72 (diff)
Intermediate changes
commit_hash:e594b985d9b571bd3d1e14ec6a75601ef80617bf
-rw-r--r--contrib/python/tenacity/py3/.dist-info/METADATA19
-rw-r--r--contrib/python/tenacity/py3/README.rst36
-rw-r--r--contrib/python/tenacity/py3/tenacity/__init__.py14
-rw-r--r--contrib/python/tenacity/py3/tenacity/asyncio/__init__.py13
-rw-r--r--contrib/python/tenacity/py3/tenacity/before_sleep.py4
-rw-r--r--contrib/python/tenacity/py3/tenacity/retry.py4
-rw-r--r--contrib/python/tenacity/py3/tenacity/wait.py2
-rw-r--r--contrib/python/tenacity/py3/ya.make2
8 files changed, 67 insertions, 27 deletions
diff --git a/contrib/python/tenacity/py3/.dist-info/METADATA b/contrib/python/tenacity/py3/.dist-info/METADATA
index cd789a8975c..8fa59d2b13f 100644
--- a/contrib/python/tenacity/py3/.dist-info/METADATA
+++ b/contrib/python/tenacity/py3/.dist-info/METADATA
@@ -1,6 +1,6 @@
-Metadata-Version: 2.1
+Metadata-Version: 2.4
Name: tenacity
-Version: 8.4.1
+Version: 9.1.2
Summary: Retry code until it succeeds
Home-page: https://github.com/jd/tenacity
Author: Julien Danjou
@@ -11,20 +11,21 @@ Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
-Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
+Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Utilities
-Requires-Python: >=3.8
+Requires-Python: >=3.9
License-File: LICENSE
Provides-Extra: doc
-Requires-Dist: reno ; extra == 'doc'
-Requires-Dist: sphinx ; extra == 'doc'
+Requires-Dist: reno; extra == "doc"
+Requires-Dist: sphinx; extra == "doc"
Provides-Extra: test
-Requires-Dist: pytest ; extra == 'test'
-Requires-Dist: tornado >=4.5 ; extra == 'test'
-Requires-Dist: typeguard ; extra == 'test'
+Requires-Dist: pytest; extra == "test"
+Requires-Dist: tornado>=4.5; extra == "test"
+Requires-Dist: typeguard; extra == "test"
+Dynamic: license-file
Tenacity is a general-purpose retrying library to simplify the task of adding retry behavior to just about anything.
diff --git a/contrib/python/tenacity/py3/README.rst b/contrib/python/tenacity/py3/README.rst
index 65dd208bdfe..928ddd99b91 100644
--- a/contrib/python/tenacity/py3/README.rst
+++ b/contrib/python/tenacity/py3/README.rst
@@ -124,8 +124,8 @@ retrying stuff.
print("Stopping after 10 seconds")
raise Exception
-If you're on a tight deadline, and exceeding your delay time isn't ok,
-then you can give up on retries one attempt before you would exceed the delay.
+If you're on a tight deadline, and exceeding your delay time isn't ok,
+then you can give up on retries one attempt before you would exceed the delay.
.. testcode::
@@ -362,7 +362,7 @@ Statistics
~~~~~~~~~~
You can access the statistics about the retry made over a function by using the
-`retry` attribute attached to the function and its `statistics` attribute:
+`statistics` attribute attached to the function:
.. testcode::
@@ -375,7 +375,7 @@ You can access the statistics about the retry made over a function by using the
except Exception:
pass
- print(raise_my_exception.retry.statistics)
+ print(raise_my_exception.statistics)
.. testoutput::
:hide:
@@ -495,7 +495,7 @@ using the `retry_with` function attached to the wrapped function:
except Exception:
pass
- print(raise_my_exception.retry.statistics)
+ print(raise_my_exception.statistics)
.. testoutput::
:hide:
@@ -514,6 +514,32 @@ to use the `retry` decorator - you can instead use `Retrying` directly:
retryer = Retrying(stop=stop_after_attempt(max_attempts), reraise=True)
retryer(never_good_enough, 'I really do try')
+You may also want to change the behaviour of a decorated function temporarily,
+like in tests to avoid unnecessary wait times. You can modify/patch the `retry`
+attribute attached to the function. Bear in mind this is a write-only attribute,
+statistics should be read from the function `statistics` attribute.
+
+.. testcode::
+
+ @retry(stop=stop_after_attempt(3), wait=wait_fixed(3))
+ def raise_my_exception():
+ raise MyException("Fail")
+
+ from unittest import mock
+
+ with mock.patch.object(raise_my_exception.retry, "wait", wait_fixed(0)):
+ try:
+ raise_my_exception()
+ except Exception:
+ pass
+
+ print(raise_my_exception.statistics)
+
+.. testoutput::
+ :hide:
+
+ ...
+
Retrying code block
~~~~~~~~~~~~~~~~~~~
diff --git a/contrib/python/tenacity/py3/tenacity/__init__.py b/contrib/python/tenacity/py3/tenacity/__init__.py
index 7de36d43457..e274c215575 100644
--- a/contrib/python/tenacity/py3/tenacity/__init__.py
+++ b/contrib/python/tenacity/py3/tenacity/__init__.py
@@ -76,7 +76,7 @@ from .before import before_nothing # noqa
from .after import after_log # noqa
from .after import after_nothing # noqa
-# Import all built-in after strategies for easier usage.
+# Import all built-in before sleep strategies for easier usage.
from .before_sleep import before_sleep_log # noqa
from .before_sleep import before_sleep_nothing # noqa
@@ -88,6 +88,8 @@ except ImportError:
if t.TYPE_CHECKING:
import types
+ from typing_extensions import Self
+
from . import asyncio as tasyncio
from .retry import RetryBaseT
from .stop import StopBaseT
@@ -255,7 +257,7 @@ class BaseRetrying(ABC):
retry_error_callback: t.Union[
t.Optional[t.Callable[["RetryCallState"], t.Any]], object
] = _unset,
- ) -> "BaseRetrying":
+ ) -> "Self":
"""Copy this object with some parameters changed if needed."""
return self.__class__(
sleep=_first_set(sleep, self.sleep),
@@ -329,13 +331,19 @@ class BaseRetrying(ABC):
f, functools.WRAPPER_ASSIGNMENTS + ("__defaults__", "__kwdefaults__")
)
def wrapped_f(*args: t.Any, **kw: t.Any) -> t.Any:
- return self(f, *args, **kw)
+ # Always create a copy to prevent overwriting the local contexts when
+ # calling the same wrapped functions multiple times in the same stack
+ copy = self.copy()
+ wrapped_f.statistics = copy.statistics # type: ignore[attr-defined]
+ return copy(f, *args, **kw)
def retry_with(*args: t.Any, **kwargs: t.Any) -> WrappedFn:
return self.copy(*args, **kwargs).wraps(f)
+ # Preserve attributes
wrapped_f.retry = self # type: ignore[attr-defined]
wrapped_f.retry_with = retry_with # type: ignore[attr-defined]
+ wrapped_f.statistics = {} # type: ignore[attr-defined]
return wrapped_f # type: ignore[return-value]
diff --git a/contrib/python/tenacity/py3/tenacity/asyncio/__init__.py b/contrib/python/tenacity/py3/tenacity/asyncio/__init__.py
index 6d63ebcfaba..a92609140e5 100644
--- a/contrib/python/tenacity/py3/tenacity/asyncio/__init__.py
+++ b/contrib/python/tenacity/py3/tenacity/asyncio/__init__.py
@@ -175,18 +175,23 @@ class AsyncRetrying(BaseRetrying):
raise StopAsyncIteration
def wraps(self, fn: WrappedFn) -> WrappedFn:
- fn = super().wraps(fn)
+ wrapped = super().wraps(fn)
# Ensure wrapper is recognized as a coroutine function.
@functools.wraps(
fn, functools.WRAPPER_ASSIGNMENTS + ("__defaults__", "__kwdefaults__")
)
async def async_wrapped(*args: t.Any, **kwargs: t.Any) -> t.Any:
- return await fn(*args, **kwargs)
+ # Always create a copy to prevent overwriting the local contexts when
+ # calling the same wrapped functions multiple times in the same stack
+ copy = self.copy()
+ async_wrapped.statistics = copy.statistics # type: ignore[attr-defined]
+ return await copy(fn, *args, **kwargs)
# Preserve attributes
- async_wrapped.retry = fn.retry # type: ignore[attr-defined]
- async_wrapped.retry_with = fn.retry_with # type: ignore[attr-defined]
+ async_wrapped.retry = self # type: ignore[attr-defined]
+ async_wrapped.retry_with = wrapped.retry_with # type: ignore[attr-defined]
+ async_wrapped.statistics = {} # type: ignore[attr-defined]
return async_wrapped # type: ignore[return-value]
diff --git a/contrib/python/tenacity/py3/tenacity/before_sleep.py b/contrib/python/tenacity/py3/tenacity/before_sleep.py
index d04edcf9bd8..153edb7acbb 100644
--- a/contrib/python/tenacity/py3/tenacity/before_sleep.py
+++ b/contrib/python/tenacity/py3/tenacity/before_sleep.py
@@ -25,7 +25,7 @@ if typing.TYPE_CHECKING:
def before_sleep_nothing(retry_state: "RetryCallState") -> None:
- """Before call strategy that does nothing."""
+ """Before sleep strategy that does nothing."""
def before_sleep_log(
@@ -33,7 +33,7 @@ def before_sleep_log(
log_level: int,
exc_info: bool = False,
) -> typing.Callable[["RetryCallState"], None]:
- """Before call strategy that logs to some logger the attempt."""
+ """Before sleep strategy that logs to some logger the attempt."""
def log_it(retry_state: "RetryCallState") -> None:
local_exc_info: BaseException | bool | None
diff --git a/contrib/python/tenacity/py3/tenacity/retry.py b/contrib/python/tenacity/py3/tenacity/retry.py
index 9211631bd8c..9f099ec06c3 100644
--- a/contrib/python/tenacity/py3/tenacity/retry.py
+++ b/contrib/python/tenacity/py3/tenacity/retry.py
@@ -207,7 +207,7 @@ class retry_if_exception_message(retry_if_exception):
def __init__(
self,
message: typing.Optional[str] = None,
- match: typing.Optional[str] = None,
+ match: typing.Union[None, str, typing.Pattern[str]] = None,
) -> None:
if message and match:
raise TypeError(
@@ -242,7 +242,7 @@ class retry_if_not_exception_message(retry_if_exception_message):
def __init__(
self,
message: typing.Optional[str] = None,
- match: typing.Optional[str] = None,
+ match: typing.Union[None, str, typing.Pattern[str]] = None,
) -> None:
super().__init__(message, match)
# invert predicate
diff --git a/contrib/python/tenacity/py3/tenacity/wait.py b/contrib/python/tenacity/py3/tenacity/wait.py
index 3addbb9c4a2..dc3c8505ac4 100644
--- a/contrib/python/tenacity/py3/tenacity/wait.py
+++ b/contrib/python/tenacity/py3/tenacity/wait.py
@@ -197,7 +197,7 @@ class wait_random_exponential(wait_exponential):
def __call__(self, retry_state: "RetryCallState") -> float:
high = super().__call__(retry_state=retry_state)
- return random.uniform(0, high)
+ return random.uniform(self.min, high)
class wait_exponential_jitter(wait_base):
diff --git a/contrib/python/tenacity/py3/ya.make b/contrib/python/tenacity/py3/ya.make
index d75e15b99f4..56cf178d140 100644
--- a/contrib/python/tenacity/py3/ya.make
+++ b/contrib/python/tenacity/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(8.4.1)
+VERSION(9.1.2)
LICENSE(Apache-2.0)