haiway 0.10.17__py3-none-any.whl → 0.11.1__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.
haiway/__init__.py CHANGED
@@ -9,7 +9,9 @@ from haiway.context import (
9
9
  MetricsScopeExiting,
10
10
  MissingContext,
11
11
  MissingState,
12
+ ScopeContext,
12
13
  ScopeIdentifier,
14
+ StateContext,
13
15
  ctx,
14
16
  )
15
17
  from haiway.helpers import (
@@ -78,8 +80,10 @@ __all__ = [
78
80
  "MissingContext",
79
81
  "MissingState",
80
82
  "ResultTrace",
83
+ "ScopeContext",
81
84
  "ScopeIdentifier",
82
85
  "State",
86
+ "StateContext",
83
87
  "always",
84
88
  "as_dict",
85
89
  "as_list",
@@ -1,4 +1,4 @@
1
- from haiway.context.access import ctx
1
+ from haiway.context.access import ScopeContext, ctx
2
2
  from haiway.context.disposables import Disposable, Disposables
3
3
  from haiway.context.identifier import ScopeIdentifier
4
4
  from haiway.context.metrics import (
@@ -9,6 +9,7 @@ from haiway.context.metrics import (
9
9
  MetricsScopeEntering,
10
10
  MetricsScopeExiting,
11
11
  )
12
+ from haiway.context.state import StateContext
12
13
  from haiway.context.types import MissingContext, MissingState
13
14
 
14
15
  __all__ = [
@@ -22,6 +23,8 @@ __all__ = [
22
23
  "MetricsScopeExiting",
23
24
  "MissingContext",
24
25
  "MissingState",
26
+ "ScopeContext",
25
27
  "ScopeIdentifier",
28
+ "StateContext",
26
29
  "ctx",
27
30
  ]
haiway/context/access.py CHANGED
@@ -1,4 +1,9 @@
1
- from asyncio import CancelledError, Task, current_task, iscoroutinefunction
1
+ from asyncio import (
2
+ CancelledError,
3
+ Task,
4
+ current_task,
5
+ iscoroutinefunction,
6
+ )
2
7
  from collections.abc import (
3
8
  AsyncGenerator,
4
9
  AsyncIterator,
haiway/helpers/tracing.py CHANGED
@@ -1,6 +1,6 @@
1
1
  from asyncio import iscoroutinefunction
2
2
  from collections.abc import Callable, Coroutine, Mapping, Sequence
3
- from typing import Any, Self, cast
3
+ from typing import Any, Self, cast, overload
4
4
 
5
5
  from haiway.context import ctx
6
6
  from haiway.state import State
@@ -61,28 +61,53 @@ class ResultTrace(State):
61
61
  result: Any | Missing
62
62
 
63
63
 
64
+ @overload
64
65
  def traced[**Args, Result](
65
66
  function: Callable[Args, Result],
66
67
  /,
67
- ) -> Callable[Args, Result]:
68
- if __debug__:
69
- if iscoroutinefunction(function):
70
- return cast(
71
- Callable[Args, Result],
72
- _traced_async(
73
- function,
74
- label=function.__name__,
75
- ),
76
- )
68
+ ) -> Callable[Args, Result]: ...
69
+
70
+
71
+ @overload
72
+ def traced[**Args, Result](
73
+ *,
74
+ label: str,
75
+ ) -> Callable[[Callable[Args, Result]], Callable[Args, Result]]: ...
77
76
 
78
- else:
79
- return _traced_sync(
80
- function,
81
- label=function.__name__,
82
- )
83
77
 
84
- else: # do not trace on non debug runs
85
- return function
78
+ def traced[**Args, Result](
79
+ function: Callable[Args, Result] | None = None,
80
+ /,
81
+ *,
82
+ label: str | None = None,
83
+ ) -> Callable[[Callable[Args, Result]], Callable[Args, Result]] | Callable[Args, Result]:
84
+ def wrap(
85
+ wrapped: Callable[Args, Result],
86
+ ) -> Callable[Args, Result]:
87
+ if __debug__:
88
+ if iscoroutinefunction(wrapped):
89
+ return cast(
90
+ Callable[Args, Result],
91
+ _traced_async(
92
+ wrapped,
93
+ label=label or wrapped.__name__,
94
+ ),
95
+ )
96
+
97
+ else:
98
+ return _traced_sync(
99
+ wrapped,
100
+ label=label or wrapped.__name__,
101
+ )
102
+
103
+ else: # do not trace on non debug runs
104
+ return wrapped
105
+
106
+ if function := function:
107
+ return wrap(wrapped=function)
108
+
109
+ else:
110
+ return wrap
86
111
 
87
112
 
88
113
  def _traced_sync[**Args, Result](
haiway/utils/queue.py CHANGED
@@ -23,9 +23,6 @@ class AsyncQueue[Element](AsyncIterator[Element]):
23
23
  self._waiting: Future[Element] | None = None
24
24
  self._finish_reason: BaseException | None = None
25
25
 
26
- def __del__(self) -> None:
27
- self.finish()
28
-
29
26
  @property
30
27
  def is_finished(self) -> bool:
31
28
  return self._finish_reason is not None
@@ -34,7 +31,6 @@ class AsyncQueue[Element](AsyncIterator[Element]):
34
31
  self,
35
32
  element: Element,
36
33
  /,
37
- *elements: Element,
38
34
  ) -> None:
39
35
  if self.is_finished:
40
36
  raise RuntimeError("AsyncQueue is already finished")
@@ -45,8 +41,6 @@ class AsyncQueue[Element](AsyncIterator[Element]):
45
41
  else:
46
42
  self._queue.append(element)
47
43
 
48
- self._queue.extend(elements)
49
-
50
44
  def finish(
51
45
  self,
52
46
  exception: BaseException | None = None,
@@ -57,7 +51,17 @@ class AsyncQueue[Element](AsyncIterator[Element]):
57
51
  self._finish_reason = exception or StopAsyncIteration()
58
52
 
59
53
  if self._waiting is not None and not self._waiting.done():
60
- self._waiting.set_exception(self._finish_reason)
54
+ # checking loop only on finish as the rest of operations
55
+ # should always have a valid loop in a typical environment
56
+ # and we are not supporting multithreading yet
57
+ if get_running_loop() is not self._loop:
58
+ self._loop.call_soon_threadsafe(
59
+ self._waiting.set_exception,
60
+ self._finish_reason,
61
+ )
62
+
63
+ else:
64
+ self._waiting.set_exception(self._finish_reason)
61
65
 
62
66
  def cancel(self) -> None:
63
67
  self.finish(exception=CancelledError())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haiway
3
- Version: 0.10.17
3
+ Version: 0.11.1
4
4
  Summary: Framework for dependency injection and state management within structured concurrency model.
5
5
  Project-URL: Homepage, https://miquido.com
6
6
  Project-URL: Repository, https://github.com/miquido/haiway.git
@@ -1,7 +1,7 @@
1
- haiway/__init__.py,sha256=IEUCyFYKT5IPHnkiUvDVZHdJeHqCaBnG8FhPD20Zgo8,1929
1
+ haiway/__init__.py,sha256=PYMHx7JZwwSsALewho7v6EgIb5MUwYgZEWrVH-OhVx0,2005
2
2
  haiway/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- haiway/context/__init__.py,sha256=eRvuhifx7xCd-_6desgk55idzNpD5S5sprmCfGb3_9M,662
4
- haiway/context/access.py,sha256=Fc2NfoIV2zWE5qPnNgSitK1dy-PME-rJJfUPhoNwJzY,17125
3
+ haiway/context/__init__.py,sha256=feqd0eJnGQwh4B8BZXpS0fQRE-DqoFCFOHipF1jOY8A,762
4
+ haiway/context/access.py,sha256=KeAgxGf78TufqEUSwvw2LPY2aPE00z6xo3hvQ8L6QO4,17146
5
5
  haiway/context/disposables.py,sha256=DZjnMp-wMfF-em2Wjhbm1MvXubNpuzFBT70BQNIxC7M,2019
6
6
  haiway/context/identifier.py,sha256=Fyb6OHx5FPaSLLRK249HUEr_KlBSG5F-eW01Oxg_Ke8,2570
7
7
  haiway/context/logging.py,sha256=ptwgENuyw-WFgokVsYx9OXZGhJENuO_wgfVjcBryUKM,4251
@@ -16,7 +16,7 @@ haiway/helpers/metrics.py,sha256=0oFBiO-hAzihyC5jvXevNrYOoTcUGc2yGhE1A_866Mc,133
16
16
  haiway/helpers/retries.py,sha256=gIkyUlqJLDYaxIZd3qzeqGFY9y5Gp8dgZLlZ6hs8hoc,7538
17
17
  haiway/helpers/throttling.py,sha256=zo0OwFq64si5KUwhd58cFHLmGAmYwRbFRJMbv9suhPs,3844
18
18
  haiway/helpers/timeouted.py,sha256=1xU09hQnFdj6p48BwZl5xUvtIr3zC0ZUXehkdrduCjs,3074
19
- haiway/helpers/tracing.py,sha256=VDOAhdVELaYs92HxHreEo_ZV8b7e6ZQs10lTNn8xOtQ,3383
19
+ haiway/helpers/tracing.py,sha256=8Gpcc_DguuHAdaxM4rGP0mB-S-8E7DKt7ZGym9f6x6Q,4018
20
20
  haiway/state/__init__.py,sha256=emTuwGFn7HyjyTJ_ass69J5jQIA7_WHO4teZz_dR05Y,355
21
21
  haiway/state/attributes.py,sha256=plCcYGE5LVU1Nvo0GHkhThqFG96uLR3tFsisQyK1jK0,23122
22
22
  haiway/state/path.py,sha256=p-ZVSDU02qAUDln12SDc1pGWzhZ88-1zYEBC0hqceXM,17930
@@ -35,8 +35,8 @@ haiway/utils/freezing.py,sha256=K34ZIMzbkpgkHKH-KF73plEbXExsajNRkRTYp9nJEf4,620
35
35
  haiway/utils/logs.py,sha256=oDsc1ZdqKDjlTlctLbDcp9iX98Acr-1tdw-Pyg3DElo,1577
36
36
  haiway/utils/mimic.py,sha256=BkVjTVP2TxxC8GChPGyDV6UXVwJmiRiSWeOYZNZFHxs,1828
37
37
  haiway/utils/noop.py,sha256=qgbZlOKWY6_23Zs43OLukK2HagIQKRyR04zrFVm5rWI,344
38
- haiway/utils/queue.py,sha256=oQ3GXCJ-PGNtMEr6EPdgqAvYZoj8lAa7Z2drBKBEoBM,2345
39
- haiway-0.10.17.dist-info/METADATA,sha256=IwCgN_53mbzSI8qNibPFrXQT_pwJnA34YxZY1BNdrc8,3858
40
- haiway-0.10.17.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
41
- haiway-0.10.17.dist-info/licenses/LICENSE,sha256=GehQEW_I1pkmxkkj3NEa7rCTQKYBn7vTPabpDYJlRuo,1063
42
- haiway-0.10.17.dist-info/RECORD,,
38
+ haiway/utils/queue.py,sha256=jmz5b4cDvdXpuFnAfrNsGB5wXx4ThCgLHbFlH54o8UY,2657
39
+ haiway-0.11.1.dist-info/METADATA,sha256=RAlc7LEyW8N7fizrJI0n_E1e52LlDscJDuEnD_nJdAM,3857
40
+ haiway-0.11.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
41
+ haiway-0.11.1.dist-info/licenses/LICENSE,sha256=GehQEW_I1pkmxkkj3NEa7rCTQKYBn7vTPabpDYJlRuo,1063
42
+ haiway-0.11.1.dist-info/RECORD,,