haiway 0.1.0__tar.gz → 0.2.0__tar.gz
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.
- {haiway-0.1.0/src/haiway.egg-info → haiway-0.2.0}/PKG-INFO +1 -1
- {haiway-0.1.0 → haiway-0.2.0}/pyproject.toml +1 -1
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/__init__.py +8 -18
- haiway-0.2.0/src/haiway/context/__init__.py +10 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/context/access.py +7 -29
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/context/metrics.py +11 -11
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/context/state.py +15 -17
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/context/types.py +0 -5
- haiway-0.2.0/src/haiway/helpers/__init__.py +16 -0
- haiway-0.1.0/src/haiway/helpers/cache.py → haiway-0.2.0/src/haiway/helpers/cached.py +4 -4
- haiway-0.2.0/src/haiway/helpers/disposables.py +65 -0
- haiway-0.1.0/src/haiway/helpers/retry.py → haiway-0.2.0/src/haiway/helpers/retries.py +20 -7
- haiway-0.1.0/src/haiway/helpers/timeout.py → haiway-0.2.0/src/haiway/helpers/timeouted.py +2 -2
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/state/__init__.py +2 -2
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/state/attributes.py +1 -1
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/state/structure.py +17 -17
- {haiway-0.1.0 → haiway-0.2.0/src/haiway.egg-info}/PKG-INFO +1 -1
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway.egg-info/SOURCES.txt +5 -5
- {haiway-0.1.0 → haiway-0.2.0}/tests/test_auto_retry.py +18 -18
- {haiway-0.1.0 → haiway-0.2.0}/tests/test_cache.py +18 -18
- {haiway-0.1.0 → haiway-0.2.0}/tests/test_context.py +2 -2
- haiway-0.1.0/tests/test_structure.py → haiway-0.2.0/tests/test_state.py +7 -7
- {haiway-0.1.0 → haiway-0.2.0}/tests/test_timeout.py +5 -5
- haiway-0.1.0/src/haiway/context/__init__.py +0 -14
- haiway-0.1.0/src/haiway/context/dependencies.py +0 -61
- haiway-0.1.0/src/haiway/helpers/__init__.py +0 -13
- {haiway-0.1.0 → haiway-0.2.0}/LICENSE +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/README.md +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/setup.cfg +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/context/tasks.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/helpers/asynchronous.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/helpers/throttling.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/py.typed +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/state/validation.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/types/__init__.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/types/frozen.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/types/missing.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/utils/__init__.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/utils/always.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/utils/env.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/utils/immutable.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/utils/logs.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/utils/mimic.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/utils/noop.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway/utils/queue.py +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway.egg-info/dependency_links.txt +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway.egg-info/requires.txt +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/src/haiway.egg-info/top_level.txt +0 -0
- {haiway-0.1.0 → haiway-0.2.0}/tests/test_async_queue.py +0 -0
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|
5
5
|
[project]
|
6
6
|
name = "haiway"
|
7
7
|
description = "Framework for dependency injection and state management within structured concurrency model."
|
8
|
-
version = "0.
|
8
|
+
version = "0.2.0"
|
9
9
|
readme = "README.md"
|
10
10
|
maintainers = [
|
11
11
|
{ name = "Kacper Kaliński", email = "kacper.kalinski@miquido.com" },
|
@@ -1,20 +1,11 @@
|
|
1
1
|
from haiway.context import (
|
2
|
-
Dependencies,
|
3
|
-
Dependency,
|
4
2
|
MissingContext,
|
5
|
-
MissingDependency,
|
6
3
|
MissingState,
|
7
4
|
ScopeMetrics,
|
8
5
|
ctx,
|
9
6
|
)
|
10
|
-
from haiway.helpers import
|
11
|
-
|
12
|
-
auto_retry,
|
13
|
-
cached,
|
14
|
-
throttle,
|
15
|
-
with_timeout,
|
16
|
-
)
|
17
|
-
from haiway.state import Structure
|
7
|
+
from haiway.helpers import Disposable, Disposables, asynchronous, cache, retry, throttle, timeout
|
8
|
+
from haiway.state import State
|
18
9
|
from haiway.types import (
|
19
10
|
MISSING,
|
20
11
|
Missing,
|
@@ -45,11 +36,10 @@ __all__ = [
|
|
45
36
|
"async_noop",
|
46
37
|
"asynchronous",
|
47
38
|
"AsyncQueue",
|
48
|
-
"
|
49
|
-
"cached",
|
39
|
+
"cache",
|
50
40
|
"ctx",
|
51
|
-
"
|
52
|
-
"
|
41
|
+
"Disposable",
|
42
|
+
"Disposables",
|
53
43
|
"freeze",
|
54
44
|
"frozenlist",
|
55
45
|
"getenv_bool",
|
@@ -62,14 +52,14 @@ __all__ = [
|
|
62
52
|
"Missing",
|
63
53
|
"MISSING",
|
64
54
|
"MissingContext",
|
65
|
-
"MissingDependency",
|
66
55
|
"MissingState",
|
67
56
|
"noop",
|
68
57
|
"not_missing",
|
58
|
+
"retry",
|
69
59
|
"ScopeMetrics",
|
70
60
|
"setup_logging",
|
71
|
-
"
|
61
|
+
"State",
|
72
62
|
"throttle",
|
63
|
+
"timeout",
|
73
64
|
"when_missing",
|
74
|
-
"with_timeout",
|
75
65
|
]
|
@@ -10,11 +10,10 @@ from logging import Logger
|
|
10
10
|
from types import TracebackType
|
11
11
|
from typing import Any, final
|
12
12
|
|
13
|
-
from haiway.context.dependencies import Dependencies, Dependency
|
14
13
|
from haiway.context.metrics import MetricsContext, ScopeMetrics
|
15
14
|
from haiway.context.state import StateContext
|
16
15
|
from haiway.context.tasks import TaskGroupContext
|
17
|
-
from haiway.state import
|
16
|
+
from haiway.state import State
|
18
17
|
from haiway.utils import freeze
|
19
18
|
|
20
19
|
__all__ = [
|
@@ -101,7 +100,7 @@ class ctx:
|
|
101
100
|
def scope(
|
102
101
|
name: str,
|
103
102
|
/,
|
104
|
-
*state:
|
103
|
+
*state: State,
|
105
104
|
logger: Logger | None = None,
|
106
105
|
trace_id: str | None = None,
|
107
106
|
completion: Callable[[ScopeMetrics], Coroutine[None, None, None]] | None = None,
|
@@ -115,7 +114,7 @@ class ctx:
|
|
115
114
|
name: Value
|
116
115
|
name of the scope context
|
117
116
|
|
118
|
-
*state:
|
117
|
+
*state: State
|
119
118
|
state propagated within the scope context, will be merged with current if any\
|
120
119
|
by replacing current with provided on conflict
|
121
120
|
|
@@ -152,7 +151,7 @@ class ctx:
|
|
152
151
|
|
153
152
|
@staticmethod
|
154
153
|
def updated(
|
155
|
-
*state:
|
154
|
+
*state: State,
|
156
155
|
) -> StateContext:
|
157
156
|
"""
|
158
157
|
Update scope context with given state. When called within an existing context\
|
@@ -160,7 +159,7 @@ class ctx:
|
|
160
159
|
|
161
160
|
Parameters
|
162
161
|
----------
|
163
|
-
*state:
|
162
|
+
*state: State
|
164
163
|
state propagated within the updated scope context, will be merged with current if any\
|
165
164
|
by replacing current with provided on conflict
|
166
165
|
|
@@ -215,28 +214,7 @@ class ctx:
|
|
215
214
|
raise RuntimeError("Attempting to cancel context out of asyncio task")
|
216
215
|
|
217
216
|
@staticmethod
|
218
|
-
|
219
|
-
dependency: type[DependencyType],
|
220
|
-
/,
|
221
|
-
) -> DependencyType:
|
222
|
-
"""
|
223
|
-
Access current dependency by its type.
|
224
|
-
|
225
|
-
Parameters
|
226
|
-
----------
|
227
|
-
dependency: type[DependencyType]
|
228
|
-
type of requested dependency
|
229
|
-
|
230
|
-
Returns
|
231
|
-
-------
|
232
|
-
DependencyType
|
233
|
-
resolved dependency instance
|
234
|
-
"""
|
235
|
-
|
236
|
-
return await Dependencies.dependency(dependency)
|
237
|
-
|
238
|
-
@staticmethod
|
239
|
-
def state[StateType: Structure](
|
217
|
+
def state[StateType: State](
|
240
218
|
state: type[StateType],
|
241
219
|
/,
|
242
220
|
default: StateType | None = None,
|
@@ -261,7 +239,7 @@ class ctx:
|
|
261
239
|
)
|
262
240
|
|
263
241
|
@staticmethod
|
264
|
-
def record[Metric:
|
242
|
+
def record[Metric: State](
|
265
243
|
metric: Metric,
|
266
244
|
/,
|
267
245
|
merge: Callable[[Metric, Metric], Metric] = lambda lhs, rhs: rhs,
|
@@ -9,7 +9,7 @@ from types import TracebackType
|
|
9
9
|
from typing import Any, Self, cast, final, overload
|
10
10
|
from uuid import uuid4
|
11
11
|
|
12
|
-
from haiway.state import
|
12
|
+
from haiway.state import State
|
13
13
|
from haiway.utils import freeze
|
14
14
|
|
15
15
|
__all__ = [
|
@@ -30,7 +30,7 @@ class ScopeMetrics:
|
|
30
30
|
self.trace_id: str = trace_id or uuid4().hex
|
31
31
|
self._label: str = f"{self.trace_id}|{scope}" if scope else self.trace_id
|
32
32
|
self._logger: Logger = logger or getLogger(name=scope)
|
33
|
-
self._metrics: dict[type[
|
33
|
+
self._metrics: dict[type[State], State] = {}
|
34
34
|
self._nested: list[ScopeMetrics] = []
|
35
35
|
self._timestamp: float = monotonic()
|
36
36
|
self._completed: Future[float] = get_event_loop().create_future()
|
@@ -46,11 +46,11 @@ class ScopeMetrics:
|
|
46
46
|
def metrics(
|
47
47
|
self,
|
48
48
|
*,
|
49
|
-
merge: Callable[[
|
50
|
-
) -> list[
|
51
|
-
metrics: dict[type[
|
49
|
+
merge: Callable[[State, State], State] = lambda lhs, rhs: lhs,
|
50
|
+
) -> list[State]:
|
51
|
+
metrics: dict[type[State], State] = copy(self._metrics)
|
52
52
|
for metric in chain.from_iterable(nested.metrics(merge=merge) for nested in self._nested):
|
53
|
-
metric_type: type[
|
53
|
+
metric_type: type[State] = type(metric)
|
54
54
|
if current := metrics.get(metric_type):
|
55
55
|
metrics[metric_type] = merge(current, metric)
|
56
56
|
|
@@ -60,21 +60,21 @@ class ScopeMetrics:
|
|
60
60
|
return list(metrics.values())
|
61
61
|
|
62
62
|
@overload
|
63
|
-
def read[Metric:
|
63
|
+
def read[Metric: State](
|
64
64
|
self,
|
65
65
|
metric: type[Metric],
|
66
66
|
/,
|
67
67
|
) -> Metric | None: ...
|
68
68
|
|
69
69
|
@overload
|
70
|
-
def read[Metric:
|
70
|
+
def read[Metric: State](
|
71
71
|
self,
|
72
72
|
metric: type[Metric],
|
73
73
|
/,
|
74
74
|
default: Metric,
|
75
75
|
) -> Metric: ...
|
76
76
|
|
77
|
-
def read[Metric:
|
77
|
+
def read[Metric: State](
|
78
78
|
self,
|
79
79
|
metric: type[Metric],
|
80
80
|
/,
|
@@ -82,7 +82,7 @@ class ScopeMetrics:
|
|
82
82
|
) -> Metric | None:
|
83
83
|
return cast(Metric | None, self._metrics.get(metric, default))
|
84
84
|
|
85
|
-
def record[Metric:
|
85
|
+
def record[Metric: State](
|
86
86
|
self,
|
87
87
|
metric: Metric,
|
88
88
|
/,
|
@@ -187,7 +187,7 @@ class MetricsContext:
|
|
187
187
|
)
|
188
188
|
|
189
189
|
@classmethod
|
190
|
-
def record[Metric:
|
190
|
+
def record[Metric: State](
|
191
191
|
cls,
|
192
192
|
metric: Metric,
|
193
193
|
/,
|
@@ -4,7 +4,7 @@ from types import TracebackType
|
|
4
4
|
from typing import Self, cast, final
|
5
5
|
|
6
6
|
from haiway.context.types import MissingContext, MissingState
|
7
|
-
from haiway.state import
|
7
|
+
from haiway.state import State
|
8
8
|
from haiway.utils import freeze
|
9
9
|
|
10
10
|
__all__ = [
|
@@ -17,28 +17,26 @@ __all__ = [
|
|
17
17
|
class ScopeState:
|
18
18
|
def __init__(
|
19
19
|
self,
|
20
|
-
state: Iterable[
|
20
|
+
state: Iterable[State],
|
21
21
|
) -> None:
|
22
|
-
self._state: dict[type[
|
23
|
-
type(element): element for element in state
|
24
|
-
}
|
22
|
+
self._state: dict[type[State], State] = {type(element): element for element in state}
|
25
23
|
freeze(self)
|
26
24
|
|
27
|
-
def state[
|
25
|
+
def state[StateType: State](
|
28
26
|
self,
|
29
|
-
state: type[
|
27
|
+
state: type[StateType],
|
30
28
|
/,
|
31
|
-
default:
|
32
|
-
) ->
|
29
|
+
default: StateType | None = None,
|
30
|
+
) -> StateType:
|
33
31
|
if state in self._state:
|
34
|
-
return cast(
|
32
|
+
return cast(StateType, self._state[state])
|
35
33
|
|
36
34
|
elif default is not None:
|
37
35
|
return default
|
38
36
|
|
39
37
|
else:
|
40
38
|
try:
|
41
|
-
initialized:
|
39
|
+
initialized: StateType = state()
|
42
40
|
self._state[state] = initialized
|
43
41
|
return initialized
|
44
42
|
|
@@ -50,7 +48,7 @@ class ScopeState:
|
|
50
48
|
|
51
49
|
def updated(
|
52
50
|
self,
|
53
|
-
state: Iterable[
|
51
|
+
state: Iterable[State],
|
54
52
|
) -> Self:
|
55
53
|
if state:
|
56
54
|
return self.__class__(
|
@@ -69,12 +67,12 @@ class StateContext:
|
|
69
67
|
_context = ContextVar[ScopeState]("StateContext")
|
70
68
|
|
71
69
|
@classmethod
|
72
|
-
def current[
|
70
|
+
def current[StateType: State](
|
73
71
|
cls,
|
74
|
-
state: type[
|
72
|
+
state: type[StateType],
|
75
73
|
/,
|
76
|
-
default:
|
77
|
-
) ->
|
74
|
+
default: StateType | None = None,
|
75
|
+
) -> StateType:
|
78
76
|
try:
|
79
77
|
return cls._context.get().state(state, default=default)
|
80
78
|
|
@@ -84,7 +82,7 @@ class StateContext:
|
|
84
82
|
@classmethod
|
85
83
|
def updated(
|
86
84
|
cls,
|
87
|
-
state: Iterable[
|
85
|
+
state: Iterable[State],
|
88
86
|
/,
|
89
87
|
) -> Self:
|
90
88
|
try:
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from haiway.helpers.asynchronous import asynchronous
|
2
|
+
from haiway.helpers.cached import cache
|
3
|
+
from haiway.helpers.disposables import Disposable, Disposables
|
4
|
+
from haiway.helpers.retries import retry
|
5
|
+
from haiway.helpers.throttling import throttle
|
6
|
+
from haiway.helpers.timeouted import timeout
|
7
|
+
|
8
|
+
__all__ = [
|
9
|
+
"asynchronous",
|
10
|
+
"cache",
|
11
|
+
"Disposable",
|
12
|
+
"Disposables",
|
13
|
+
"retry",
|
14
|
+
"throttle",
|
15
|
+
"timeout",
|
16
|
+
]
|
@@ -9,26 +9,26 @@ from weakref import ref
|
|
9
9
|
from haiway.utils.mimic import mimic_function
|
10
10
|
|
11
11
|
__all__ = [
|
12
|
-
"
|
12
|
+
"cache",
|
13
13
|
]
|
14
14
|
|
15
15
|
|
16
16
|
@overload
|
17
|
-
def
|
17
|
+
def cache[**Args, Result](
|
18
18
|
function: Callable[Args, Result],
|
19
19
|
/,
|
20
20
|
) -> Callable[Args, Result]: ...
|
21
21
|
|
22
22
|
|
23
23
|
@overload
|
24
|
-
def
|
24
|
+
def cache[**Args, Result](
|
25
25
|
*,
|
26
26
|
limit: int = 1,
|
27
27
|
expiration: float | None = None,
|
28
28
|
) -> Callable[[Callable[Args, Result]], Callable[Args, Result]]: ...
|
29
29
|
|
30
30
|
|
31
|
-
def
|
31
|
+
def cache[**Args, Result](
|
32
32
|
function: Callable[Args, Result] | None = None,
|
33
33
|
*,
|
34
34
|
limit: int = 1,
|
@@ -0,0 +1,65 @@
|
|
1
|
+
from asyncio import gather, shield
|
2
|
+
from collections.abc import Iterable
|
3
|
+
from types import TracebackType
|
4
|
+
from typing import Protocol, final, runtime_checkable
|
5
|
+
|
6
|
+
from haiway.state import State
|
7
|
+
|
8
|
+
__all__ = [
|
9
|
+
"Disposable",
|
10
|
+
"Disposables",
|
11
|
+
]
|
12
|
+
|
13
|
+
|
14
|
+
@runtime_checkable
|
15
|
+
class Disposable(Protocol):
|
16
|
+
async def initialize(self) -> State | None: ...
|
17
|
+
async def dispose(self) -> None: ...
|
18
|
+
|
19
|
+
|
20
|
+
@final
|
21
|
+
class Disposables:
|
22
|
+
def __init__(
|
23
|
+
self,
|
24
|
+
*disposables: Disposable,
|
25
|
+
) -> None:
|
26
|
+
self._disposables: tuple[Disposable, ...] = disposables
|
27
|
+
|
28
|
+
async def initialize(self) -> Iterable[State]:
|
29
|
+
return [
|
30
|
+
state
|
31
|
+
for state in await gather(
|
32
|
+
*[disposable.initialize() for disposable in self._disposables],
|
33
|
+
)
|
34
|
+
if state is not None
|
35
|
+
]
|
36
|
+
|
37
|
+
async def dispose(self) -> None:
|
38
|
+
results: list[BaseException | None] = await shield(
|
39
|
+
gather(
|
40
|
+
*[disposable.dispose() for disposable in self._disposables],
|
41
|
+
return_exceptions=True,
|
42
|
+
),
|
43
|
+
)
|
44
|
+
|
45
|
+
self._disposables = ()
|
46
|
+
exceptions: list[BaseException] = [
|
47
|
+
exception for exception in results if exception is not None
|
48
|
+
]
|
49
|
+
|
50
|
+
if len(exceptions) > 1:
|
51
|
+
raise BaseExceptionGroup("Disposing errors", exceptions)
|
52
|
+
|
53
|
+
elif exceptions:
|
54
|
+
raise exceptions[0]
|
55
|
+
|
56
|
+
async def __aenter__(self) -> Iterable[State]:
|
57
|
+
return await self.initialize()
|
58
|
+
|
59
|
+
async def __aexit__(
|
60
|
+
self,
|
61
|
+
exc_type: type[BaseException] | None,
|
62
|
+
exc_val: BaseException | None,
|
63
|
+
exc_tb: TracebackType | None,
|
64
|
+
) -> None:
|
65
|
+
await self.dispose()
|
@@ -1,17 +1,18 @@
|
|
1
1
|
from asyncio import CancelledError, iscoroutinefunction, sleep
|
2
2
|
from collections.abc import Callable, Coroutine
|
3
|
+
from time import sleep as sleep_sync
|
3
4
|
from typing import cast, overload
|
4
5
|
|
5
6
|
from haiway.context import ctx
|
6
7
|
from haiway.utils import mimic_function
|
7
8
|
|
8
9
|
__all__ = [
|
9
|
-
"
|
10
|
+
"retry",
|
10
11
|
]
|
11
12
|
|
12
13
|
|
13
14
|
@overload
|
14
|
-
def
|
15
|
+
def retry[**Args, Result](
|
15
16
|
function: Callable[Args, Result],
|
16
17
|
/,
|
17
18
|
) -> Callable[Args, Result]:
|
@@ -34,7 +35,7 @@ def auto_retry[**Args, Result](
|
|
34
35
|
|
35
36
|
|
36
37
|
@overload
|
37
|
-
def
|
38
|
+
def retry[**Args, Result](
|
38
39
|
*,
|
39
40
|
limit: int = 1,
|
40
41
|
delay: Callable[[int, Exception], float] | float | None = None,
|
@@ -66,7 +67,7 @@ def auto_retry[**Args, Result](
|
|
66
67
|
"""
|
67
68
|
|
68
69
|
|
69
|
-
def
|
70
|
+
def retry[**Args, Result](
|
70
71
|
function: Callable[Args, Result] | None = None,
|
71
72
|
*,
|
72
73
|
limit: int = 1,
|
@@ -115,11 +116,12 @@ def auto_retry[**Args, Result](
|
|
115
116
|
catching=catching if isinstance(catching, set | tuple) else {catching},
|
116
117
|
),
|
117
118
|
)
|
119
|
+
|
118
120
|
else:
|
119
|
-
assert delay is None, "Delay is not supported in sync wrapper" # nosec: B101
|
120
121
|
return _wrap_sync(
|
121
122
|
function,
|
122
123
|
limit=limit,
|
124
|
+
delay=delay,
|
123
125
|
catching=catching if isinstance(catching, set | tuple) else {catching},
|
124
126
|
)
|
125
127
|
|
@@ -133,6 +135,7 @@ def _wrap_sync[**Args, Result](
|
|
133
135
|
function: Callable[Args, Result],
|
134
136
|
*,
|
135
137
|
limit: int,
|
138
|
+
delay: Callable[[int, Exception], float] | float | None,
|
136
139
|
catching: set[type[Exception]] | tuple[type[Exception], ...],
|
137
140
|
) -> Callable[Args, Result]:
|
138
141
|
assert limit > 0, "Limit has to be greater than zero" # nosec: B101
|
@@ -158,6 +161,16 @@ def _wrap_sync[**Args, Result](
|
|
158
161
|
exc,
|
159
162
|
)
|
160
163
|
|
164
|
+
match delay:
|
165
|
+
case None:
|
166
|
+
continue
|
167
|
+
|
168
|
+
case float(strict):
|
169
|
+
sleep_sync(strict)
|
170
|
+
|
171
|
+
case make_delay: # type: Callable[[], float]
|
172
|
+
sleep_sync(make_delay(attempt, exc)) # pyright: ignore[reportCallIssue, reportUnknownArgumentType]
|
173
|
+
|
161
174
|
else:
|
162
175
|
raise exc
|
163
176
|
|
@@ -199,10 +212,10 @@ def _wrap_async[**Args, Result](
|
|
199
212
|
continue
|
200
213
|
|
201
214
|
case float(strict):
|
202
|
-
await sleep(
|
215
|
+
await sleep(strict)
|
203
216
|
|
204
217
|
case make_delay: # type: Callable[[], float]
|
205
|
-
await sleep(
|
218
|
+
await sleep(make_delay(attempt, exc)) # pyright: ignore[reportCallIssue, reportUnknownArgumentType]
|
206
219
|
|
207
220
|
else:
|
208
221
|
raise exc
|
@@ -4,11 +4,11 @@ from collections.abc import Callable, Coroutine
|
|
4
4
|
from haiway.utils.mimic import mimic_function
|
5
5
|
|
6
6
|
__all__ = [
|
7
|
-
"
|
7
|
+
"timeout",
|
8
8
|
]
|
9
9
|
|
10
10
|
|
11
|
-
def
|
11
|
+
def timeout[**Args, Result](
|
12
12
|
timeout: float,
|
13
13
|
/,
|
14
14
|
) -> Callable[
|
@@ -1,8 +1,8 @@
|
|
1
1
|
from haiway.state.attributes import AttributeAnnotation, attribute_annotations
|
2
|
-
from haiway.state.structure import
|
2
|
+
from haiway.state.structure import State
|
3
3
|
|
4
4
|
__all__ = [
|
5
5
|
"attribute_annotations",
|
6
6
|
"AttributeAnnotation",
|
7
|
-
"
|
7
|
+
"State",
|
8
8
|
]
|
@@ -52,7 +52,7 @@ def attribute_annotations(
|
|
52
52
|
|
53
53
|
self_annotation = AttributeAnnotation(
|
54
54
|
origin=cls,
|
55
|
-
arguments=[], # ignore self arguments here,
|
55
|
+
arguments=[], # ignore self arguments here, State will have them resolved at this stage
|
56
56
|
)
|
57
57
|
localns: dict[str, Any] = {cls.__name__: cls}
|
58
58
|
recursion_guard: dict[Any, AttributeAnnotation] = {cls: self_annotation}
|