haiway 0.19.5__py3-none-any.whl → 0.20.0__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 +2 -0
- haiway/context/__init__.py +2 -0
- haiway/context/access.py +88 -8
- haiway/context/disposables.py +63 -0
- haiway/context/identifier.py +81 -27
- haiway/context/observability.py +303 -7
- haiway/context/state.py +126 -0
- haiway/context/tasks.py +66 -0
- haiway/context/types.py +16 -0
- haiway/helpers/asynchrony.py +61 -12
- haiway/helpers/caching.py +31 -0
- haiway/helpers/observability.py +94 -11
- haiway/helpers/retries.py +59 -18
- haiway/helpers/throttling.py +42 -15
- haiway/helpers/timeouted.py +25 -10
- haiway/helpers/tracing.py +31 -0
- haiway/opentelemetry/observability.py +346 -29
- haiway/state/attributes.py +104 -0
- haiway/state/path.py +427 -12
- haiway/state/requirement.py +196 -0
- haiway/state/structure.py +359 -1
- haiway/state/validation.py +293 -0
- haiway/types/default.py +56 -0
- haiway/types/frozen.py +18 -0
- haiway/types/missing.py +89 -0
- haiway/utils/collections.py +36 -28
- haiway/utils/env.py +145 -13
- haiway/utils/formatting.py +27 -0
- haiway/utils/freezing.py +21 -1
- haiway/utils/noop.py +34 -2
- haiway/utils/queue.py +68 -1
- haiway/utils/stream.py +83 -0
- {haiway-0.19.5.dist-info → haiway-0.20.0.dist-info}/METADATA +1 -1
- haiway-0.20.0.dist-info/RECORD +46 -0
- haiway-0.19.5.dist-info/RECORD +0 -46
- {haiway-0.19.5.dist-info → haiway-0.20.0.dist-info}/WHEEL +0 -0
- {haiway-0.19.5.dist-info → haiway-0.20.0.dist-info}/licenses/LICENSE +0 -0
haiway/state/attributes.py
CHANGED
@@ -34,6 +34,14 @@ __all__ = (
|
|
34
34
|
|
35
35
|
@final
|
36
36
|
class AttributeAnnotation:
|
37
|
+
"""
|
38
|
+
Represents a type annotation for a State attribute with additional metadata.
|
39
|
+
|
40
|
+
This class encapsulates information about a type annotation, including its
|
41
|
+
origin type, type arguments, whether it's required, and any extra metadata.
|
42
|
+
It's used internally by the State system to track and validate attribute types.
|
43
|
+
"""
|
44
|
+
|
37
45
|
__slots__ = (
|
38
46
|
"arguments",
|
39
47
|
"extra",
|
@@ -49,6 +57,20 @@ class AttributeAnnotation:
|
|
49
57
|
required: bool = True,
|
50
58
|
extra: Mapping[str, Any] | None = None,
|
51
59
|
) -> None:
|
60
|
+
"""
|
61
|
+
Initialize a new attribute annotation.
|
62
|
+
|
63
|
+
Parameters
|
64
|
+
----------
|
65
|
+
origin : Any
|
66
|
+
The base type of the annotation (e.g., str, int, List)
|
67
|
+
arguments : Sequence[Any] | None
|
68
|
+
Type arguments for generic types (e.g., T in List[T])
|
69
|
+
required : bool
|
70
|
+
Whether this attribute is required (cannot be omitted)
|
71
|
+
extra : Mapping[str, Any] | None
|
72
|
+
Additional metadata about the annotation
|
73
|
+
"""
|
52
74
|
self.origin: Any = origin
|
53
75
|
self.arguments: Sequence[Any]
|
54
76
|
if arguments is None:
|
@@ -71,6 +93,22 @@ class AttributeAnnotation:
|
|
71
93
|
required: bool,
|
72
94
|
/,
|
73
95
|
) -> Self:
|
96
|
+
"""
|
97
|
+
Update the required flag for this annotation.
|
98
|
+
|
99
|
+
The resulting required flag is the logical AND of the current
|
100
|
+
flag and the provided value.
|
101
|
+
|
102
|
+
Parameters
|
103
|
+
----------
|
104
|
+
required : bool
|
105
|
+
New required flag value to combine with the existing one
|
106
|
+
|
107
|
+
Returns
|
108
|
+
-------
|
109
|
+
Self
|
110
|
+
This annotation with the updated required flag
|
111
|
+
"""
|
74
112
|
object.__setattr__(
|
75
113
|
self,
|
76
114
|
"required",
|
@@ -80,6 +118,17 @@ class AttributeAnnotation:
|
|
80
118
|
return self
|
81
119
|
|
82
120
|
def __str__(self) -> str:
|
121
|
+
"""
|
122
|
+
Convert this annotation to a string representation.
|
123
|
+
|
124
|
+
Returns a readable string representation of the type, including
|
125
|
+
its origin type and any type arguments.
|
126
|
+
|
127
|
+
Returns
|
128
|
+
-------
|
129
|
+
str
|
130
|
+
String representation of this annotation
|
131
|
+
"""
|
83
132
|
if alias := self.extra.get("TYPE_ALIAS"):
|
84
133
|
return alias
|
85
134
|
|
@@ -103,6 +152,29 @@ def attribute_annotations(
|
|
103
152
|
/,
|
104
153
|
type_parameters: Mapping[str, Any],
|
105
154
|
) -> Mapping[str, AttributeAnnotation]:
|
155
|
+
"""
|
156
|
+
Extract and process type annotations from a class.
|
157
|
+
|
158
|
+
This function analyzes a class's type hints and converts them to AttributeAnnotation
|
159
|
+
objects, which provide rich type information used by the State system for validation
|
160
|
+
and other type-related operations.
|
161
|
+
|
162
|
+
Parameters
|
163
|
+
----------
|
164
|
+
cls : type[Any]
|
165
|
+
The class to extract annotations from
|
166
|
+
type_parameters : Mapping[str, Any]
|
167
|
+
Type parameters to substitute in generic type annotations
|
168
|
+
|
169
|
+
Returns
|
170
|
+
-------
|
171
|
+
Mapping[str, AttributeAnnotation]
|
172
|
+
A mapping of attribute names to their processed type annotations
|
173
|
+
|
174
|
+
Notes
|
175
|
+
-----
|
176
|
+
Private attributes (prefixed with underscore) and ClassVars are ignored.
|
177
|
+
"""
|
106
178
|
self_annotation = AttributeAnnotation(
|
107
179
|
origin=cls,
|
108
180
|
# ignore arguments here, State (and draive.DataModel) will have them resolved at this stage
|
@@ -573,6 +645,38 @@ def resolve_attribute_annotation( # noqa: C901, PLR0911, PLR0912
|
|
573
645
|
self_annotation: AttributeAnnotation | None,
|
574
646
|
recursion_guard: MutableMapping[str, AttributeAnnotation],
|
575
647
|
) -> AttributeAnnotation:
|
648
|
+
"""
|
649
|
+
Resolve a Python type annotation into an AttributeAnnotation object.
|
650
|
+
|
651
|
+
This function analyzes any Python type annotation and converts it into
|
652
|
+
an AttributeAnnotation that captures its structure, including handling
|
653
|
+
for special types like unions, optionals, literals, generics, etc.
|
654
|
+
|
655
|
+
Parameters
|
656
|
+
----------
|
657
|
+
annotation : Any
|
658
|
+
The type annotation to resolve
|
659
|
+
module : str
|
660
|
+
The module where the annotation is defined (for resolving ForwardRefs)
|
661
|
+
type_parameters : Mapping[str, Any]
|
662
|
+
Type parameters to substitute in generic type annotations
|
663
|
+
self_annotation : AttributeAnnotation | None
|
664
|
+
The annotation for Self references, if available
|
665
|
+
recursion_guard : MutableMapping[str, AttributeAnnotation]
|
666
|
+
Cache to prevent infinite recursion for recursive types
|
667
|
+
|
668
|
+
Returns
|
669
|
+
-------
|
670
|
+
AttributeAnnotation
|
671
|
+
A resolved AttributeAnnotation representing the input annotation
|
672
|
+
|
673
|
+
Raises
|
674
|
+
------
|
675
|
+
RuntimeError
|
676
|
+
If a Self annotation is used but self_annotation is not provided
|
677
|
+
TypeError
|
678
|
+
If the annotation is of an unsupported type
|
679
|
+
"""
|
576
680
|
match get_origin(annotation) or annotation:
|
577
681
|
case types.NoneType | None:
|
578
682
|
return _resolve_none(
|