dycw-utilities 0.131.16__py3-none-any.whl → 0.131.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dycw_utilities-0.131.16.dist-info → dycw_utilities-0.131.18.dist-info}/METADATA +1 -1
- {dycw_utilities-0.131.16.dist-info → dycw_utilities-0.131.18.dist-info}/RECORD +18 -19
- utilities/__init__.py +1 -1
- utilities/asyncio.py +47 -60
- utilities/datetime.py +2 -279
- utilities/iterables.py +1 -30
- utilities/operator.py +21 -15
- utilities/orjson.py +67 -84
- utilities/parse.py +24 -53
- utilities/pottery.py +16 -19
- utilities/psutil.py +8 -7
- utilities/redis.py +108 -116
- utilities/slack_sdk.py +17 -18
- utilities/sqlalchemy.py +36 -30
- utilities/sqlalchemy_polars.py +12 -27
- utilities/whenever.py +2 -216
- utilities/tenacity.py +0 -145
- {dycw_utilities-0.131.16.dist-info → dycw_utilities-0.131.18.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.131.16.dist-info → dycw_utilities-0.131.18.dist-info}/licenses/LICENSE +0 -0
utilities/tenacity.py
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
from contextlib import AbstractAsyncContextManager, asynccontextmanager
|
4
|
-
from typing import TYPE_CHECKING, Any, override
|
5
|
-
|
6
|
-
from tenacity import (
|
7
|
-
AsyncRetrying,
|
8
|
-
AttemptManager,
|
9
|
-
RetryCallState,
|
10
|
-
RetryError,
|
11
|
-
after_nothing,
|
12
|
-
before_nothing,
|
13
|
-
retry_if_exception_type,
|
14
|
-
stop_never,
|
15
|
-
wait_none,
|
16
|
-
)
|
17
|
-
from tenacity import wait_exponential_jitter as _wait_exponential_jitter
|
18
|
-
from tenacity._utils import MAX_WAIT
|
19
|
-
from tenacity.asyncio import _portable_async_sleep
|
20
|
-
|
21
|
-
from utilities.asyncio import timeout_dur
|
22
|
-
from utilities.contextlib import NoOpContextManager
|
23
|
-
from utilities.datetime import datetime_duration_to_float
|
24
|
-
|
25
|
-
if TYPE_CHECKING:
|
26
|
-
from collections.abc import AsyncIterator, Callable
|
27
|
-
|
28
|
-
from tenacity.retry import RetryBaseT
|
29
|
-
from tenacity.stop import StopBaseT
|
30
|
-
from tenacity.wait import WaitBaseT
|
31
|
-
|
32
|
-
from utilities.types import Duration, MaybeAwaitable
|
33
|
-
|
34
|
-
|
35
|
-
type MaybeAttemptManager = NoOpContextManager | AttemptManager
|
36
|
-
type MaybeAttemptContextManager = AbstractAsyncContextManager[MaybeAttemptManager]
|
37
|
-
|
38
|
-
|
39
|
-
class wait_exponential_jitter(_wait_exponential_jitter): # noqa: N801
|
40
|
-
"""Subclass of `wait_exponential_jitter` accepting durations."""
|
41
|
-
|
42
|
-
@override
|
43
|
-
def __init__(
|
44
|
-
self,
|
45
|
-
initial: Duration = 1,
|
46
|
-
max: Duration = MAX_WAIT,
|
47
|
-
exp_base: float = 2,
|
48
|
-
jitter: Duration = 1,
|
49
|
-
) -> None:
|
50
|
-
super().__init__(
|
51
|
-
initial=datetime_duration_to_float(initial),
|
52
|
-
max=datetime_duration_to_float(max),
|
53
|
-
exp_base=exp_base,
|
54
|
-
jitter=datetime_duration_to_float(jitter),
|
55
|
-
)
|
56
|
-
|
57
|
-
|
58
|
-
async def yield_attempts(
|
59
|
-
*,
|
60
|
-
sleep: Callable[[int | float], MaybeAwaitable[None]] | None = None,
|
61
|
-
stop: StopBaseT | None = None,
|
62
|
-
wait: WaitBaseT | None = None,
|
63
|
-
retry: RetryBaseT | None = None,
|
64
|
-
before: Callable[[RetryCallState], MaybeAwaitable[None]] | None = None,
|
65
|
-
after: Callable[[RetryCallState], MaybeAwaitable[None]] | None = None,
|
66
|
-
before_sleep: Callable[[RetryCallState], MaybeAwaitable[None]] | None = None,
|
67
|
-
reraise: bool | None = None,
|
68
|
-
retry_error_cls: type[RetryError] | None = None,
|
69
|
-
retry_error_callback: Callable[[RetryCallState], MaybeAwaitable[Any]] | None = None,
|
70
|
-
) -> AsyncIterator[MaybeAttemptManager]:
|
71
|
-
"""Yield the attempts."""
|
72
|
-
if (
|
73
|
-
(sleep is None)
|
74
|
-
and (stop is None)
|
75
|
-
and (wait is None)
|
76
|
-
and (retry is None)
|
77
|
-
and (before is None)
|
78
|
-
and (after is None)
|
79
|
-
and (before_sleep is None)
|
80
|
-
and (reraise is None)
|
81
|
-
and (retry_error_cls is None)
|
82
|
-
):
|
83
|
-
yield NoOpContextManager()
|
84
|
-
else:
|
85
|
-
retrying = AsyncRetrying(
|
86
|
-
sleep=_portable_async_sleep if sleep is None else sleep,
|
87
|
-
stop=stop_never if stop is None else stop,
|
88
|
-
wait=wait_none() if wait is None else wait,
|
89
|
-
retry=retry_if_exception_type() if retry is None else retry,
|
90
|
-
before=before_nothing if before is None else before,
|
91
|
-
after=after_nothing if after is None else after,
|
92
|
-
before_sleep=None if before_sleep is None else before_sleep,
|
93
|
-
reraise=False if reraise is None else reraise,
|
94
|
-
retry_error_cls=RetryError if retry_error_cls is None else retry_error_cls,
|
95
|
-
retry_error_callback=retry_error_callback,
|
96
|
-
)
|
97
|
-
async for attempt in retrying:
|
98
|
-
yield attempt
|
99
|
-
|
100
|
-
|
101
|
-
async def yield_timeout_attempts(
|
102
|
-
*,
|
103
|
-
sleep: Callable[[int | float], MaybeAwaitable[None]] | None = None,
|
104
|
-
stop: StopBaseT | None = None,
|
105
|
-
wait: WaitBaseT | None = None,
|
106
|
-
retry: RetryBaseT | None = None,
|
107
|
-
before: Callable[[RetryCallState], MaybeAwaitable[None]] | None = None,
|
108
|
-
after: Callable[[RetryCallState], MaybeAwaitable[None]] | None = None,
|
109
|
-
before_sleep: Callable[[RetryCallState], MaybeAwaitable[None]] | None = None,
|
110
|
-
reraise: bool | None = None,
|
111
|
-
retry_error_cls: type[RetryError] | None = None,
|
112
|
-
retry_error_callback: Callable[[RetryCallState], MaybeAwaitable[Any]] | None = None,
|
113
|
-
timeout: Duration | None = None,
|
114
|
-
) -> AsyncIterator[MaybeAttemptContextManager]:
|
115
|
-
"""Yield the attempts, with timeout."""
|
116
|
-
async for attempt in yield_attempts(
|
117
|
-
sleep=sleep,
|
118
|
-
stop=stop,
|
119
|
-
wait=wait,
|
120
|
-
retry=retry,
|
121
|
-
before=before,
|
122
|
-
after=after,
|
123
|
-
before_sleep=before_sleep,
|
124
|
-
reraise=reraise,
|
125
|
-
retry_error_cls=retry_error_cls,
|
126
|
-
retry_error_callback=retry_error_callback,
|
127
|
-
):
|
128
|
-
|
129
|
-
@asynccontextmanager
|
130
|
-
async def new(
|
131
|
-
attempt: MaybeAttemptManager, /
|
132
|
-
) -> AsyncIterator[MaybeAttemptManager]:
|
133
|
-
with attempt:
|
134
|
-
async with timeout_dur(duration=timeout):
|
135
|
-
yield attempt
|
136
|
-
|
137
|
-
yield new(attempt)
|
138
|
-
|
139
|
-
|
140
|
-
__all__ = [
|
141
|
-
"MaybeAttemptManager",
|
142
|
-
"wait_exponential_jitter",
|
143
|
-
"yield_attempts",
|
144
|
-
"yield_timeout_attempts",
|
145
|
-
]
|
File without changes
|
File without changes
|