haiway 0.11.0__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/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](
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haiway
3
- Version: 0.11.0
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
@@ -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
@@ -36,7 +36,7 @@ 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
38
  haiway/utils/queue.py,sha256=jmz5b4cDvdXpuFnAfrNsGB5wXx4ThCgLHbFlH54o8UY,2657
39
- haiway-0.11.0.dist-info/METADATA,sha256=HWxQi7lFsvowR9D-wF-zNBHnIfMVq0i5Jlze3BAbVEo,3857
40
- haiway-0.11.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
41
- haiway-0.11.0.dist-info/licenses/LICENSE,sha256=GehQEW_I1pkmxkkj3NEa7rCTQKYBn7vTPabpDYJlRuo,1063
42
- haiway-0.11.0.dist-info/RECORD,,
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,,