haiway 0.5.0__tar.gz → 0.5.2__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.
Files changed (48) hide show
  1. {haiway-0.5.0/src/haiway.egg-info → haiway-0.5.2}/PKG-INFO +1 -1
  2. {haiway-0.5.0 → haiway-0.5.2}/pyproject.toml +1 -1
  3. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/__init__.py +2 -0
  4. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/context/metrics.py +2 -2
  5. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/helpers/__init__.py +2 -1
  6. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/helpers/asynchrony.py +17 -0
  7. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/state/structure.py +8 -2
  8. {haiway-0.5.0 → haiway-0.5.2/src/haiway.egg-info}/PKG-INFO +1 -1
  9. {haiway-0.5.0 → haiway-0.5.2}/tests/test_state.py +32 -1
  10. {haiway-0.5.0 → haiway-0.5.2}/LICENSE +0 -0
  11. {haiway-0.5.0 → haiway-0.5.2}/README.md +0 -0
  12. {haiway-0.5.0 → haiway-0.5.2}/setup.cfg +0 -0
  13. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/context/__init__.py +0 -0
  14. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/context/access.py +0 -0
  15. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/context/disposables.py +0 -0
  16. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/context/state.py +0 -0
  17. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/context/tasks.py +0 -0
  18. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/context/types.py +0 -0
  19. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/helpers/caching.py +0 -0
  20. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/helpers/retries.py +0 -0
  21. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/helpers/throttling.py +0 -0
  22. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/helpers/timeouted.py +0 -0
  23. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/helpers/tracing.py +0 -0
  24. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/py.typed +0 -0
  25. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/state/__init__.py +0 -0
  26. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/state/attributes.py +0 -0
  27. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/state/validation.py +0 -0
  28. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/types/__init__.py +0 -0
  29. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/types/frozen.py +0 -0
  30. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/types/missing.py +0 -0
  31. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/utils/__init__.py +0 -0
  32. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/utils/always.py +0 -0
  33. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/utils/env.py +0 -0
  34. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/utils/immutable.py +0 -0
  35. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/utils/logs.py +0 -0
  36. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/utils/mimic.py +0 -0
  37. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/utils/noop.py +0 -0
  38. {haiway-0.5.0 → haiway-0.5.2}/src/haiway/utils/queue.py +0 -0
  39. {haiway-0.5.0 → haiway-0.5.2}/src/haiway.egg-info/SOURCES.txt +0 -0
  40. {haiway-0.5.0 → haiway-0.5.2}/src/haiway.egg-info/dependency_links.txt +0 -0
  41. {haiway-0.5.0 → haiway-0.5.2}/src/haiway.egg-info/requires.txt +0 -0
  42. {haiway-0.5.0 → haiway-0.5.2}/src/haiway.egg-info/top_level.txt +0 -0
  43. {haiway-0.5.0 → haiway-0.5.2}/tests/test_async_queue.py +0 -0
  44. {haiway-0.5.0 → haiway-0.5.2}/tests/test_auto_retry.py +0 -0
  45. {haiway-0.5.0 → haiway-0.5.2}/tests/test_cache.py +0 -0
  46. {haiway-0.5.0 → haiway-0.5.2}/tests/test_context.py +0 -0
  47. {haiway-0.5.0 → haiway-0.5.2}/tests/test_streaming.py +0 -0
  48. {haiway-0.5.0 → haiway-0.5.2}/tests/test_timeout.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: haiway
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: Framework for dependency injection and state management within structured concurrency model.
5
5
  Maintainer-email: Kacper Kaliński <kacper.kalinski@miquido.com>
6
6
  License: MIT License
@@ -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.5.0"
8
+ version = "0.5.2"
9
9
  readme = "README.md"
10
10
  maintainers = [
11
11
  { name = "Kacper Kaliński", email = "kacper.kalinski@miquido.com" },
@@ -15,6 +15,7 @@ from haiway.helpers import (
15
15
  throttle,
16
16
  timeout,
17
17
  traced,
18
+ wrap_async,
18
19
  )
19
20
  from haiway.state import State
20
21
  from haiway.types import (
@@ -76,4 +77,5 @@ __all__ = [
76
77
  "timeout",
77
78
  "traced",
78
79
  "when_missing",
80
+ "wrap_async",
79
81
  ]
@@ -48,14 +48,14 @@ class ScopeMetrics:
48
48
  self._logger: Logger = logger or getLogger(name=scope)
49
49
  self._parent: Self | None = parent if parent else None
50
50
  self._metrics: dict[type[State], State] = {}
51
- self._nested: set[ScopeMetrics] = set()
51
+ self._nested: list[ScopeMetrics] = []
52
52
  self._timestamp: float = monotonic()
53
53
  self._finished: bool = False
54
54
  self._loop: AbstractEventLoop = get_event_loop()
55
55
  self._completed: Future[float] = self._loop.create_future()
56
56
 
57
57
  if parent := parent:
58
- parent._nested.add(self)
58
+ parent._nested.append(self)
59
59
 
60
60
  freeze(self)
61
61
 
@@ -1,4 +1,4 @@
1
- from haiway.helpers.asynchrony import asynchronous
1
+ from haiway.helpers.asynchrony import asynchronous, wrap_async
2
2
  from haiway.helpers.caching import cache
3
3
  from haiway.helpers.retries import retry
4
4
  from haiway.helpers.throttling import throttle
@@ -14,4 +14,5 @@ __all__ = [
14
14
  "throttle",
15
15
  "timeout",
16
16
  "traced",
17
+ "wrap_async",
17
18
  ]
@@ -9,9 +9,26 @@ from haiway.types.missing import MISSING, Missing
9
9
 
10
10
  __all__ = [
11
11
  "asynchronous",
12
+ "wrap_async",
12
13
  ]
13
14
 
14
15
 
16
+ def wrap_async[**Args, Result](
17
+ function: Callable[Args, Coroutine[None, None, Result]] | Callable[Args, Result],
18
+ /,
19
+ ) -> Callable[Args, Coroutine[None, None, Result]]:
20
+ if iscoroutinefunction(function):
21
+ return function
22
+
23
+ else:
24
+
25
+ async def async_function(*args: Args.args, **kwargs: Args.kwargs) -> Result:
26
+ return cast(Callable[Args, Result], function)(*args, **kwargs)
27
+
28
+ _mimic_async(function, within=async_function)
29
+ return async_function
30
+
31
+
15
32
  @overload
16
33
  def asynchronous[**Args, Result]() -> (
17
34
  Callable[
@@ -16,7 +16,7 @@ from weakref import WeakValueDictionary
16
16
 
17
17
  from haiway.state.attributes import AttributeAnnotation, attribute_annotations
18
18
  from haiway.state.validation import attribute_type_validator
19
- from haiway.types.missing import MISSING, Missing
19
+ from haiway.types import MISSING, Missing, not_missing
20
20
 
21
21
  __all__ = [
22
22
  "State",
@@ -184,7 +184,13 @@ class State(metaclass=StateMeta):
184
184
  return self.__replace__(**kwargs)
185
185
 
186
186
  def as_dict(self) -> dict[str, Any]:
187
- return vars(self)
187
+ dict_result: dict[str, Any] = {}
188
+ for key in self.__ATTRIBUTES__.keys():
189
+ value: Any | Missing = getattr(self, key, MISSING)
190
+ if not_missing(value):
191
+ dict_result[key] = value
192
+
193
+ return dict_result
188
194
 
189
195
  def __str__(self) -> str:
190
196
  attributes: str = ", ".join([f"{key}: {value}" for key, value in vars(self).items()])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: haiway
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: Framework for dependency injection and state management within structured concurrency model.
5
5
  Maintainer-email: Kacper Kaliński <kacper.kalinski@miquido.com>
6
6
  License: MIT License
@@ -1,7 +1,7 @@
1
1
  from collections.abc import Callable
2
2
  from typing import Literal, Protocol, Self, TypedDict, runtime_checkable
3
3
 
4
- from haiway import State, frozenlist
4
+ from haiway import MISSING, Missing, State, frozenlist
5
5
 
6
6
 
7
7
  def test_basic_initializes_with_arguments() -> None:
@@ -63,6 +63,17 @@ def test_basic_initializes_with_defaults() -> None:
63
63
  assert basic.optional is None
64
64
 
65
65
 
66
+ def test_basic_equals_checks_properties() -> None:
67
+ class Basics(State):
68
+ string: str
69
+ integer: int
70
+
71
+ assert Basics(string="a", integer=1) == Basics(string="a", integer=1)
72
+ assert Basics(string="a", integer=1) != Basics(string="b", integer=1)
73
+ assert Basics(string="a", integer=1) != Basics(string="a", integer=2)
74
+ assert Basics(string="a", integer=1) != Basics(string="b", integer=2)
75
+
76
+
66
77
  def test_basic_initializes_with_arguments_and_defaults() -> None:
67
78
  class Basics(State):
68
79
  string: str
@@ -119,3 +130,23 @@ def test_nested_initializes_with_proper_arguments() -> None:
119
130
  recursion=None,
120
131
  self_recursion=None,
121
132
  )
133
+
134
+
135
+ def test_dict_skips_missing_properties() -> None:
136
+ class Basics(State):
137
+ string: str
138
+ integer: int | Missing | None
139
+
140
+ assert Basics(string="a", integer=1).as_dict() == {"string": "a", "integer": 1}
141
+ assert Basics(string="a", integer=MISSING).as_dict() == {"string": "a"}
142
+ assert Basics(string="a", integer=None).as_dict() == {"string": "a", "integer": None}
143
+
144
+
145
+ def test_initialization_allows_missing_properties() -> None:
146
+ class Basics(State):
147
+ string: str
148
+ integer: int | Missing | None
149
+
150
+ assert Basics(**{"string": "a", "integer": 1}) == Basics(string="a", integer=1)
151
+ assert Basics(**{"string": "a", "integer": None}) == Basics(string="a", integer=None)
152
+ assert Basics(**{"string": "a"}) == Basics(string="a", integer=MISSING)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes