diff options
| author | Alexander Smirnov <[email protected]> | 2025-06-10 00:52:07 +0000 |
|---|---|---|
| committer | Alexander Smirnov <[email protected]> | 2025-06-10 00:52:07 +0000 |
| commit | ffd64b5598afad459996cebb3e988e10e85fdc93 (patch) | |
| tree | 85cd23cbcd813014430b2c0f43ce7c86cf2a0a1c /contrib/python | |
| parent | 715e053338895b15bbc8e7b10342ab383956c611 (diff) | |
| parent | 686b7126cb55601e05506a4a890e6f442703306b (diff) | |
Merge branch 'rightlib' into merge-libs-250610-0050
Diffstat (limited to 'contrib/python')
| -rw-r--r-- | contrib/python/freezegun/py3/.dist-info/METADATA | 58 | ||||
| -rw-r--r-- | contrib/python/freezegun/py3/README.rst | 44 | ||||
| -rw-r--r-- | contrib/python/freezegun/py3/freezegun/__init__.py | 2 | ||||
| -rw-r--r-- | contrib/python/freezegun/py3/freezegun/api.py | 53 | ||||
| -rw-r--r-- | contrib/python/freezegun/py3/ya.make | 2 | ||||
| -rw-r--r-- | contrib/python/pytest-lazy-fixtures/.dist-info/METADATA | 2 | ||||
| -rw-r--r-- | contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/normalizer.py | 2 | ||||
| -rw-r--r-- | contrib/python/pytest-lazy-fixtures/ya.make | 2 | ||||
| -rw-r--r-- | contrib/python/tenacity/py3/.dist-info/METADATA | 19 | ||||
| -rw-r--r-- | contrib/python/tenacity/py3/README.rst | 36 | ||||
| -rw-r--r-- | contrib/python/tenacity/py3/tenacity/__init__.py | 14 | ||||
| -rw-r--r-- | contrib/python/tenacity/py3/tenacity/asyncio/__init__.py | 13 | ||||
| -rw-r--r-- | contrib/python/tenacity/py3/tenacity/before_sleep.py | 4 | ||||
| -rw-r--r-- | contrib/python/tenacity/py3/tenacity/retry.py | 4 | ||||
| -rw-r--r-- | contrib/python/tenacity/py3/tenacity/wait.py | 2 | ||||
| -rw-r--r-- | contrib/python/tenacity/py3/ya.make | 2 |
16 files changed, 212 insertions, 47 deletions
diff --git a/contrib/python/freezegun/py3/.dist-info/METADATA b/contrib/python/freezegun/py3/.dist-info/METADATA index c61e501f538..fc6e39814b0 100644 --- a/contrib/python/freezegun/py3/.dist-info/METADATA +++ b/contrib/python/freezegun/py3/.dist-info/METADATA @@ -1,29 +1,29 @@ -Metadata-Version: 2.1 +Metadata-Version: 2.4 Name: freezegun -Version: 1.5.1 +Version: 1.5.2 Summary: Let your Python tests travel through time Home-page: https://github.com/spulec/freezegun Author: Steve Pulec Author-email: [email protected] -License: Apache 2.0 +License: Apache-2.0 Project-URL: Bug Tracker, https://github.com/spulec/freezegun/issues Project-URL: Changes, https://github.com/spulec/freezegun/blob/master/CHANGELOG Project-URL: Documentation, https://github.com/spulec/freezegun/blob/master/README.rst Project-URL: Source Code, https://github.com/spulec/freezegun -Classifier: License :: OSI Approved :: Apache Software License Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.7 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: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy -Requires-Python: >=3.7 +Requires-Python: >=3.8 License-File: LICENSE License-File: AUTHORS.rst -Requires-Dist: python-dateutil >=2.7 +Requires-Dist: python-dateutil>=2.7 +Dynamic: license-file FreezeGun: Let your Python tests travel through time ==================================================== @@ -81,12 +81,12 @@ Decorator @freeze_time('2013-04-09', as_kwarg='frozen_time') def test_method_decorator_works_on_unittest(self, frozen_time): self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) - self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.today()) + self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.date()) @freeze_time('2013-04-09', as_kwarg='hello') def test_method_decorator_works_on_unittest(self, **kwargs): self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) - self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.today()) + self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.date()) Context manager ~~~~~~~~~~~~~~~ @@ -258,6 +258,46 @@ FreezeGun allows moving time to specific dates. Parameter for ``move_to`` can be any valid ``freeze_time`` date (string, date, datetime). +``real_asyncio`` parameter +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +FreezeGun has an additional ``real_asyncio`` parameter which allows asyncio event loops to see real monotonic time even though time.monotonic() is frozen. This is useful to avoid breaking asyncio.sleep() and other asyncio functions that rely on monotonic time. + +.. code-block:: python + + @freeze_time("2012-01-14", real_asyncio=True) + async def test_asyncio(): + await asyncio.sleep(1) + assert datetime.datetime.now() == datetime.datetime(2012, 1, 14) + +API Documentation +~~~~~~~~~~~~~~~~~ + +Here is a succinct API documentation with all options listed: + +.. code-block:: python + + freeze_time(time_to_freeze: Optional[_Freezable]=None, tz_offset: Union[int, datetime.timedelta]=0, ignore: Optional[List[str]]=None, tick: bool=False, as_arg: bool=False, as_kwarg: str='', auto_tick_seconds: float=0, real_asyncio: bool=False) -> _freeze_time + + _freeze_time(time_to_freeze_str: Optional[_Freezable], tz_offset: Union[int, datetime.timedelta], ignore: List[str], tick: bool, as_arg: bool, as_kwarg: str, auto_tick_seconds: float, real_asyncio: Optional[bool]) + + _freeze_time.start() -> Union[StepTickTimeFactory, TickingDateTimeFactory, FrozenDateTimeFactory] + + _freeze_time.stop() -> None + + _freeze_time.move_to(target_datetime: _Freezable) -> None + + _freeze_time.tick(delta: Union[datetime.timedelta, float]=datetime.timedelta(seconds=1)) -> datetime.datetime + + _freeze_time.decorate_class(klass: Type[T2]) -> Type[T2] + + _freeze_time.decorate_coroutine(coroutine: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]] + + _freeze_time.decorate_callable(func: Callable[P, T]) -> Callable[P, T] + + _freeze_time.__enter__() -> Union[StepTickTimeFactory, TickingDateTimeFactory, FrozenDateTimeFactory] + + _freeze_time.__exit__(*args: Any) -> None Default arguments ~~~~~~~~~~~~~~~~~ diff --git a/contrib/python/freezegun/py3/README.rst b/contrib/python/freezegun/py3/README.rst index 1545d18bc88..34cdbcbafa4 100644 --- a/contrib/python/freezegun/py3/README.rst +++ b/contrib/python/freezegun/py3/README.rst @@ -54,12 +54,12 @@ Decorator @freeze_time('2013-04-09', as_kwarg='frozen_time') def test_method_decorator_works_on_unittest(self, frozen_time): self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) - self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.today()) + self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.date()) @freeze_time('2013-04-09', as_kwarg='hello') def test_method_decorator_works_on_unittest(self, **kwargs): self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) - self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.today()) + self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.date()) Context manager ~~~~~~~~~~~~~~~ @@ -231,6 +231,46 @@ FreezeGun allows moving time to specific dates. Parameter for ``move_to`` can be any valid ``freeze_time`` date (string, date, datetime). +``real_asyncio`` parameter +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +FreezeGun has an additional ``real_asyncio`` parameter which allows asyncio event loops to see real monotonic time even though time.monotonic() is frozen. This is useful to avoid breaking asyncio.sleep() and other asyncio functions that rely on monotonic time. + +.. code-block:: python + + @freeze_time("2012-01-14", real_asyncio=True) + async def test_asyncio(): + await asyncio.sleep(1) + assert datetime.datetime.now() == datetime.datetime(2012, 1, 14) + +API Documentation +~~~~~~~~~~~~~~~~~ + +Here is a succinct API documentation with all options listed: + +.. code-block:: python + + freeze_time(time_to_freeze: Optional[_Freezable]=None, tz_offset: Union[int, datetime.timedelta]=0, ignore: Optional[List[str]]=None, tick: bool=False, as_arg: bool=False, as_kwarg: str='', auto_tick_seconds: float=0, real_asyncio: bool=False) -> _freeze_time + + _freeze_time(time_to_freeze_str: Optional[_Freezable], tz_offset: Union[int, datetime.timedelta], ignore: List[str], tick: bool, as_arg: bool, as_kwarg: str, auto_tick_seconds: float, real_asyncio: Optional[bool]) + + _freeze_time.start() -> Union[StepTickTimeFactory, TickingDateTimeFactory, FrozenDateTimeFactory] + + _freeze_time.stop() -> None + + _freeze_time.move_to(target_datetime: _Freezable) -> None + + _freeze_time.tick(delta: Union[datetime.timedelta, float]=datetime.timedelta(seconds=1)) -> datetime.datetime + + _freeze_time.decorate_class(klass: Type[T2]) -> Type[T2] + + _freeze_time.decorate_coroutine(coroutine: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]] + + _freeze_time.decorate_callable(func: Callable[P, T]) -> Callable[P, T] + + _freeze_time.__enter__() -> Union[StepTickTimeFactory, TickingDateTimeFactory, FrozenDateTimeFactory] + + _freeze_time.__exit__(*args: Any) -> None Default arguments ~~~~~~~~~~~~~~~~~ diff --git a/contrib/python/freezegun/py3/freezegun/__init__.py b/contrib/python/freezegun/py3/freezegun/__init__.py index cab37a3f7e0..ca3524f77fd 100644 --- a/contrib/python/freezegun/py3/freezegun/__init__.py +++ b/contrib/python/freezegun/py3/freezegun/__init__.py @@ -9,7 +9,7 @@ from .api import freeze_time from .config import configure __title__ = 'freezegun' -__version__ = '1.5.1' +__version__ = '1.5.2' __author__ = 'Steve Pulec' __license__ = 'Apache License 2.0' __copyright__ = 'Copyright 2012 Steve Pulec' diff --git a/contrib/python/freezegun/py3/freezegun/api.py b/contrib/python/freezegun/py3/freezegun/api.py index d2352926e46..0799162fdb0 100644 --- a/contrib/python/freezegun/py3/freezegun/api.py +++ b/contrib/python/freezegun/py3/freezegun/api.py @@ -580,6 +580,35 @@ class StepTickTimeFactory: class _freeze_time: + """ + A class to freeze time for testing purposes. + + This class can be used as a context manager or a decorator to freeze time + during the execution of a block of code or a function. It provides various + options to customize the behavior of the frozen time. + + Attributes: + time_to_freeze (datetime.datetime): The datetime to freeze time at. + tz_offset (datetime.timedelta): The timezone offset to apply to the frozen time. + ignore (List[str]): A list of module names to ignore when freezing time. + tick (bool): Whether to allow time to tick forward. + auto_tick_seconds (float): The number of seconds to auto-tick the frozen time. + undo_changes (List[Tuple[types.ModuleType, str, Any]]): A list of changes to undo when stopping the frozen time. + modules_at_start (Set[str]): A set of module names that were loaded at the start of freezing time. + as_arg (bool): Whether to pass the frozen time as an argument to the decorated function. + as_kwarg (str): The name of the keyword argument to pass the frozen time to the decorated function. + real_asyncio (Optional[bool]): Whether to allow asyncio event loops to see real monotonic time. + + Methods: + __call__(func): Decorates a function or class to freeze time during its execution. + decorate_class(klass): Decorates a class to freeze time during its execution. + __enter__(): Starts freezing time and returns the time factory. + __exit__(*args): Stops freezing time. + start(): Starts freezing time and returns the time factory. + stop(): Stops freezing time and restores the original time functions. + decorate_coroutine(coroutine): Decorates a coroutine to freeze time during its execution. + decorate_callable(func): Decorates a callable to freeze time during its execution. + """ def __init__( self, @@ -604,10 +633,6 @@ class _freeze_time: self.real_asyncio = real_asyncio @overload - def __call__(self, func: Type[T2]) -> Type[T2]: - ... - - @overload def __call__(self, func: "Callable[P, Awaitable[Any]]") -> "Callable[P, Awaitable[Any]]": ... @@ -890,6 +915,26 @@ class _freeze_time: def freeze_time(time_to_freeze: Optional[_Freezable]=None, tz_offset: Union[int, datetime.timedelta]=0, ignore: Optional[List[str]]=None, tick: bool=False, as_arg: bool=False, as_kwarg: str='', auto_tick_seconds: float=0, real_asyncio: bool=False) -> _freeze_time: + """ + Freezes time for testing purposes. + + This function can be used as a decorator or a context manager to freeze time + during the execution of a block of code or a function. It provides various + options to customize the behavior of the frozen time. + + Args: + time_to_freeze (Optional[_Freezable]): The datetime to freeze time at. + tz_offset (Union[int, datetime.timedelta]): The timezone offset to apply to the frozen time. + ignore (Optional[List[str]]): A list of module names to ignore when freezing time. + tick (bool): Whether to allow time to tick forward. + as_arg (bool): Whether to pass the frozen time as an argument to the decorated function. + as_kwarg (str): The name of the keyword argument to pass the frozen time to the decorated function. + auto_tick_seconds (float): The number of seconds to auto-tick the frozen time. + real_asyncio (bool): Whether to allow asyncio event loops to see real monotonic time. + + Returns: + _freeze_time: An instance of the _freeze_time class. + """ acceptable_times: Any = (type(None), str, datetime.date, datetime.timedelta, types.FunctionType, types.GeneratorType) diff --git a/contrib/python/freezegun/py3/ya.make b/contrib/python/freezegun/py3/ya.make index fc4d4bf1ba3..4bec269f46c 100644 --- a/contrib/python/freezegun/py3/ya.make +++ b/contrib/python/freezegun/py3/ya.make @@ -4,7 +4,7 @@ PY3_LIBRARY() PROVIDES(freezegun) -VERSION(1.5.1) +VERSION(1.5.2) LICENSE(Apache-2.0) diff --git a/contrib/python/pytest-lazy-fixtures/.dist-info/METADATA b/contrib/python/pytest-lazy-fixtures/.dist-info/METADATA index 1b4fad41ee3..09a569a800c 100644 --- a/contrib/python/pytest-lazy-fixtures/.dist-info/METADATA +++ b/contrib/python/pytest-lazy-fixtures/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: pytest-lazy-fixtures -Version: 1.1.2 +Version: 1.1.3 Summary: Allows you to use fixtures in @pytest.mark.parametrize. Home-page: https://github.com/dev-petrov/pytest-lazy-fixtures License: MIT diff --git a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/normalizer.py b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/normalizer.py index db4cfa8b00b..45a1243d52b 100644 --- a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/normalizer.py +++ b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/normalizer.py @@ -72,7 +72,7 @@ def _normalize_call(callspec, metafunc, used_keys): fixturenames_closure, arg2fixturedefs = _get_fixturenames_closure_and_arg2fixturedefs(fm, metafunc, value) if fixturenames_closure and arg2fixturedefs: - extra_fixturenames = [fname for fname in fixturenames_closure if fname not in params] + extra_fixturenames = [fname for fname in set(fixturenames_closure) if fname not in params] newmetafunc = _copy_metafunc(metafunc) newmetafunc.fixturenames = extra_fixturenames diff --git a/contrib/python/pytest-lazy-fixtures/ya.make b/contrib/python/pytest-lazy-fixtures/ya.make index fd0a21e535a..1ccca305eb0 100644 --- a/contrib/python/pytest-lazy-fixtures/ya.make +++ b/contrib/python/pytest-lazy-fixtures/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(1.1.2) +VERSION(1.1.3) LICENSE(MIT) 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) |
