ez-a-sync 0.22.14__py3-none-any.whl → 0.22.15__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.

Potentially problematic release.


This version of ez-a-sync might be problematic. Click here for more details.

Files changed (73) hide show
  1. a_sync/ENVIRONMENT_VARIABLES.py +4 -3
  2. a_sync/__init__.py +30 -12
  3. a_sync/_smart.py +132 -28
  4. a_sync/_typing.py +56 -12
  5. a_sync/a_sync/__init__.py +35 -10
  6. a_sync/a_sync/_descriptor.py +74 -26
  7. a_sync/a_sync/_flags.py +14 -6
  8. a_sync/a_sync/_helpers.py +8 -7
  9. a_sync/a_sync/_kwargs.py +3 -2
  10. a_sync/a_sync/_meta.py +120 -28
  11. a_sync/a_sync/abstract.py +102 -28
  12. a_sync/a_sync/base.py +34 -16
  13. a_sync/a_sync/config.py +47 -13
  14. a_sync/a_sync/decorator.py +239 -117
  15. a_sync/a_sync/function.py +416 -146
  16. a_sync/a_sync/method.py +197 -59
  17. a_sync/a_sync/modifiers/__init__.py +47 -5
  18. a_sync/a_sync/modifiers/cache/__init__.py +46 -17
  19. a_sync/a_sync/modifiers/cache/memory.py +86 -20
  20. a_sync/a_sync/modifiers/limiter.py +52 -22
  21. a_sync/a_sync/modifiers/manager.py +98 -16
  22. a_sync/a_sync/modifiers/semaphores.py +48 -15
  23. a_sync/a_sync/property.py +383 -82
  24. a_sync/a_sync/singleton.py +1 -0
  25. a_sync/aliases.py +0 -1
  26. a_sync/asyncio/__init__.py +4 -1
  27. a_sync/asyncio/as_completed.py +177 -49
  28. a_sync/asyncio/create_task.py +31 -17
  29. a_sync/asyncio/gather.py +72 -52
  30. a_sync/asyncio/utils.py +3 -3
  31. a_sync/exceptions.py +78 -23
  32. a_sync/executor.py +118 -71
  33. a_sync/future.py +575 -158
  34. a_sync/iter.py +110 -50
  35. a_sync/primitives/__init__.py +14 -2
  36. a_sync/primitives/_debug.py +13 -13
  37. a_sync/primitives/_loggable.py +5 -4
  38. a_sync/primitives/locks/__init__.py +5 -2
  39. a_sync/primitives/locks/counter.py +38 -36
  40. a_sync/primitives/locks/event.py +21 -7
  41. a_sync/primitives/locks/prio_semaphore.py +182 -62
  42. a_sync/primitives/locks/semaphore.py +78 -77
  43. a_sync/primitives/queue.py +560 -58
  44. a_sync/sphinx/__init__.py +0 -1
  45. a_sync/sphinx/ext.py +160 -50
  46. a_sync/task.py +262 -97
  47. a_sync/utils/__init__.py +12 -6
  48. a_sync/utils/iterators.py +127 -43
  49. {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.15.dist-info}/METADATA +1 -1
  50. ez_a_sync-0.22.15.dist-info/RECORD +74 -0
  51. {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.15.dist-info}/WHEEL +1 -1
  52. tests/conftest.py +1 -2
  53. tests/executor.py +112 -9
  54. tests/fixtures.py +61 -32
  55. tests/test_abstract.py +7 -4
  56. tests/test_as_completed.py +54 -21
  57. tests/test_base.py +66 -17
  58. tests/test_cache.py +31 -15
  59. tests/test_decorator.py +54 -28
  60. tests/test_executor.py +8 -13
  61. tests/test_future.py +45 -8
  62. tests/test_gather.py +8 -2
  63. tests/test_helpers.py +2 -0
  64. tests/test_iter.py +55 -13
  65. tests/test_limiter.py +5 -3
  66. tests/test_meta.py +23 -9
  67. tests/test_modified.py +4 -1
  68. tests/test_semaphore.py +15 -8
  69. tests/test_singleton.py +15 -10
  70. tests/test_task.py +126 -28
  71. ez_a_sync-0.22.14.dist-info/RECORD +0 -74
  72. {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.15.dist-info}/LICENSE.txt +0 -0
  73. {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.15.dist-info}/top_level.txt +0 -0
a_sync/future.py CHANGED
@@ -1,5 +1,26 @@
1
1
  # type: ignore [var-annotated]
2
2
 
3
+ """
4
+ The future.py module provides functionality for handling asynchronous futures,
5
+ including a decorator for converting callables into ASyncFuture objects and
6
+ utilities for managing asynchronous computations.
7
+
8
+ Functions:
9
+ future(callable: Union[Callable[P, Awaitable[T]], Callable[P, T]] = None, **kwargs: Unpack[ModifierKwargs]) -> Callable[P, Union[T, "ASyncFuture[T]"]]:
10
+ A decorator to convert a callable into an ASyncFuture, with optional modifiers.
11
+ _gather_check_and_materialize(*things: Unpack[MaybeAwaitable[T]]) -> List[T]:
12
+ Gathers and materializes a list of awaitable or non-awaitable items.
13
+ _check_and_materialize(thing: T) -> T:
14
+ Checks if an item is awaitable and materializes it.
15
+ _materialize(meta: "ASyncFuture[T]") -> T:
16
+ Materializes the result of an ASyncFuture.
17
+
18
+ Classes:
19
+ ASyncFuture: Represents an asynchronous future result.
20
+ _ASyncFutureWrappedFn: A callable class to wrap functions and return ASyncFuture objects.
21
+ _ASyncFutureInstanceMethod: A class to handle instance methods wrapped as ASyncFuture.
22
+ """
23
+
3
24
  import asyncio
4
25
  import concurrent.futures
5
26
  from functools import partial, wraps
@@ -8,507 +29,902 @@ from inspect import isawaitable
8
29
  from a_sync._typing import *
9
30
 
10
31
 
11
- def future(callable: Union[Callable[P, Awaitable[T]], Callable[P, T]] = None, **kwargs: Unpack[ModifierKwargs]) -> Callable[P, Union[T, "ASyncFuture[T]"]]:
32
+ def future(
33
+ callable: AnyFn[P, T] = None,
34
+ **kwargs: Unpack[ModifierKwargs],
35
+ ) -> Callable[P, Union[T, "ASyncFuture[T]"]]:
36
+ """
37
+ A decorator function to convert a callable into an ASyncFuture, with optional modifiers.
38
+
39
+ Args:
40
+ callable: The callable to convert. Defaults to None.
41
+ **kwargs: Additional keyword arguments for the modifier.
42
+ """
12
43
  return _ASyncFutureWrappedFn(callable, **kwargs)
13
44
 
45
+
14
46
  async def _gather_check_and_materialize(*things: Unpack[MaybeAwaitable[T]]) -> List[T]:
47
+ """
48
+ Gathers and materializes a list of awaitable or non-awaitable items.
49
+
50
+ Args:
51
+ *things: Items to gather and materialize.
52
+ """
15
53
  return await asyncio.gather(*[_check_and_materialize(thing) for thing in things])
16
54
 
55
+
17
56
  async def _check_and_materialize(thing: T) -> T:
57
+ """
58
+ Checks if an item is awaitable and materializes it.
59
+
60
+ Args:
61
+ thing: The item to check and materialize.
62
+ """
18
63
  return await thing if isawaitable(thing) else thing
19
-
64
+
65
+
20
66
  def _materialize(meta: "ASyncFuture[T]") -> T:
67
+ """
68
+ Materializes the result of an ASyncFuture.
69
+
70
+ Args:
71
+ meta: The ASyncFuture to materialize.
72
+
73
+ Raises:
74
+ RuntimeError: If the event loop is running and the result cannot be awaited.
75
+ """
21
76
  try:
22
77
  return asyncio.get_event_loop().run_until_complete(meta)
23
78
  except RuntimeError as e:
24
- raise RuntimeError(f"{meta} result is not set and the event loop is running, you will need to await it first") from e
79
+ raise RuntimeError(
80
+ f"{meta} result is not set and the event loop is running, you will need to await it first"
81
+ ) from e
82
+
83
+
84
+ MetaNumeric = Union[
85
+ Numeric, "ASyncFuture[int]", "ASyncFuture[float]", "ASyncFuture[Decimal]"
86
+ ]
25
87
 
26
- MetaNumeric = Union[Numeric, "ASyncFuture[int]", "ASyncFuture[float]", "ASyncFuture[Decimal]"]
27
88
 
28
89
  class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
90
+ """
91
+ A class representing an asynchronous future result.
92
+
93
+ Inherits from both concurrent.futures.Future and Awaitable[T], allowing it to be used in both synchronous and asynchronous contexts.
94
+ """
95
+
29
96
  __slots__ = "__awaitable__", "__dependencies", "__dependants", "__task"
30
-
31
- def __init__(self, awaitable: Awaitable[T], dependencies: List["ASyncFuture"] = []) -> None:
97
+
98
+ def __init__(
99
+ self, awaitable: Awaitable[T], dependencies: List["ASyncFuture"] = []
100
+ ) -> None:
101
+ """
102
+ Initializes an ASyncFuture with an awaitable and optional dependencies.
103
+
104
+ Args:
105
+ awaitable: The awaitable object.
106
+ dependencies: A list of dependencies. Defaults to [].
107
+ """
32
108
  self.__awaitable__ = awaitable
109
+ """The awaitable object."""
33
110
  self.__dependencies = dependencies
111
+ """A list of dependencies."""
34
112
  for dependency in dependencies:
35
113
  assert isinstance(dependency, ASyncFuture)
36
114
  dependency.__dependants.append(self)
37
115
  self.__dependants: List[ASyncFuture] = []
116
+ """A list of dependants."""
38
117
  self.__task = None
118
+ """The task associated with the awaitable."""
39
119
  super().__init__()
120
+
40
121
  def __hash__(self) -> int:
41
122
  return hash(self.__awaitable__)
123
+
42
124
  def __repr__(self) -> str:
43
125
  string = f"<{self.__class__.__name__} {self._state} for {self.__awaitable__}"
44
126
  if self.cancelled():
45
127
  pass
46
128
  elif self.done():
47
- string += f" exception={self.exception()}" if self.exception() else f" result={super().result()}"
129
+ string += (
130
+ f" exception={self.exception()}"
131
+ if self.exception()
132
+ else f" result={super().result()}"
133
+ )
48
134
  return string + ">"
135
+
49
136
  def __list_dependencies(self, other) -> List["ASyncFuture"]:
137
+ """
138
+ Lists dependencies for the ASyncFuture.
139
+
140
+ Args:
141
+ other: The other dependency to list.
142
+ """
50
143
  if isinstance(other, ASyncFuture):
51
144
  return [self, other]
52
145
  return [self]
146
+
53
147
  @property
54
148
  def result(self) -> Union[Callable[[], T], Any]:
55
149
  """
56
150
  If this future is not done, it will work like cf.Future.result. It will block, await the awaitable, and return the result when ready.
57
- If this future is done and the result has attribute `results`, will return `getattr(future_result, 'result')`
58
- If this future is done and the result does NOT have attribute `results`, will again work like cf.Future.result
151
+ If this future is done and the result has attribute `result`, will return `getattr(future_result, 'result')`
152
+ If this future is done and the result does NOT have attribute `result`, will again work like cf.Future.result
59
153
  """
60
154
  if self.done():
61
- if hasattr(r := super().result(), 'result'):
155
+ if hasattr(r := super().result(), "result"):
62
156
  # can be property, method, whatever. should work.
63
157
  return r.result
64
158
  # the result should be callable like an asyncio.Future
65
159
  return super().result
66
160
  return lambda: _materialize(self)
161
+
67
162
  def __getattr__(self, attr: str) -> Any:
68
163
  return getattr(_materialize(self), attr)
164
+
69
165
  def __getitem__(self, key) -> Any:
70
166
  return _materialize(self)[key]
167
+
71
168
  # NOTE: broken, do not use. I think
72
169
  def __setitem__(self, key, value) -> None:
73
170
  _materialize(self)[key] = value
171
+
74
172
  # not sure what to call these
75
173
  def __contains__(self, key: Any) -> bool:
76
- return _materialize(ASyncFuture(self.__contains(key), dependencies=self.__list_dependencies(key)))
174
+ return _materialize(
175
+ ASyncFuture(
176
+ self.__contains(key), dependencies=self.__list_dependencies(key)
177
+ )
178
+ )
179
+
77
180
  def __await__(self) -> Generator[Any, None, T]:
181
+ """
182
+ Makes the ASyncFuture awaitable.
183
+ """
78
184
  return self.__await().__await__()
185
+
79
186
  async def __await(self) -> T:
80
187
  if not self.done():
81
188
  self.set_result(await self.__task__)
82
189
  return self._result
190
+
83
191
  @property
84
192
  def __task__(self) -> "asyncio.Task[T]":
193
+ """
194
+ Returns the asyncio task associated with the awaitable, creating it if necessary.
195
+ """
85
196
  if self.__task is None:
86
197
  self.__task = asyncio.create_task(self.__awaitable__)
87
198
  return self.__task
199
+
88
200
  def __iter__(self):
89
201
  return _materialize(self).__iter__()
202
+
90
203
  def __next__(self):
91
204
  return _materialize(self).__next__()
205
+
92
206
  def __enter__(self):
93
207
  return _materialize(self).__enter__()
208
+
94
209
  def __exit__(self, *args):
95
210
  return _materialize(self).__exit__(*args)
211
+
96
212
  @overload
97
- def __add__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
213
+ def __add__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
98
214
  @overload
99
- def __add__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
215
+ def __add__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
100
216
  @overload
101
- def __add__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
217
+ def __add__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
102
218
  @overload
103
- def __add__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
219
+ def __add__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
104
220
  @overload
105
- def __add__(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
221
+ def __add__(
222
+ self: "ASyncFuture[Decimal]", other: Decimal
223
+ ) -> "ASyncFuture[Decimal]": ...
106
224
  @overload
107
- def __add__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
225
+ def __add__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]": ...
108
226
  @overload
109
- def __add__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
227
+ def __add__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]": ...
110
228
  @overload
111
- def __add__(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
229
+ def __add__(
230
+ self: "ASyncFuture[int]", other: Awaitable[int]
231
+ ) -> "ASyncFuture[int]": ...
112
232
  @overload
113
- def __add__(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
233
+ def __add__(
234
+ self: "ASyncFuture[float]", other: Awaitable[float]
235
+ ) -> "ASyncFuture[float]": ...
114
236
  @overload
115
- def __add__(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
237
+ def __add__(
238
+ self: "ASyncFuture[float]", other: Awaitable[int]
239
+ ) -> "ASyncFuture[float]": ...
116
240
  @overload
117
- def __add__(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
241
+ def __add__(
242
+ self: "ASyncFuture[int]", other: Awaitable[float]
243
+ ) -> "ASyncFuture[float]": ...
118
244
  @overload
119
- def __add__(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
245
+ def __add__(
246
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
247
+ ) -> "ASyncFuture[Decimal]": ...
120
248
  @overload
121
- def __add__(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
249
+ def __add__(
250
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
251
+ ) -> "ASyncFuture[Decimal]": ...
122
252
  @overload
123
- def __add__(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
253
+ def __add__(
254
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
255
+ ) -> "ASyncFuture[Decimal]": ...
124
256
  def __add__(self, other: MetaNumeric) -> "ASyncFuture":
125
- return ASyncFuture(self.__add(other), dependencies=self.__list_dependencies(other))
257
+ return ASyncFuture(
258
+ self.__add(other), dependencies=self.__list_dependencies(other)
259
+ )
260
+
126
261
  @overload
127
- def __sub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
262
+ def __sub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
128
263
  @overload
129
- def __sub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
264
+ def __sub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
130
265
  @overload
131
- def __sub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
266
+ def __sub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
132
267
  @overload
133
- def __sub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
268
+ def __sub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
134
269
  @overload
135
- def __sub__(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
270
+ def __sub__(
271
+ self: "ASyncFuture[Decimal]", other: Decimal
272
+ ) -> "ASyncFuture[Decimal]": ...
136
273
  @overload
137
- def __sub__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
274
+ def __sub__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]": ...
138
275
  @overload
139
- def __sub__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
276
+ def __sub__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]": ...
140
277
  @overload
141
- def __sub__(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
278
+ def __sub__(
279
+ self: "ASyncFuture[int]", other: Awaitable[int]
280
+ ) -> "ASyncFuture[int]": ...
142
281
  @overload
143
- def __sub__(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
282
+ def __sub__(
283
+ self: "ASyncFuture[float]", other: Awaitable[float]
284
+ ) -> "ASyncFuture[float]": ...
144
285
  @overload
145
- def __sub__(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
286
+ def __sub__(
287
+ self: "ASyncFuture[float]", other: Awaitable[int]
288
+ ) -> "ASyncFuture[float]": ...
146
289
  @overload
147
- def __sub__(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
290
+ def __sub__(
291
+ self: "ASyncFuture[int]", other: Awaitable[float]
292
+ ) -> "ASyncFuture[float]": ...
148
293
  @overload
149
- def __sub__(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
294
+ def __sub__(
295
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
296
+ ) -> "ASyncFuture[Decimal]": ...
150
297
  @overload
151
- def __sub__(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
298
+ def __sub__(
299
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
300
+ ) -> "ASyncFuture[Decimal]": ...
152
301
  @overload
153
- def __sub__(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
302
+ def __sub__(
303
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
304
+ ) -> "ASyncFuture[Decimal]": ...
154
305
  def __sub__(self, other: MetaNumeric) -> "ASyncFuture":
155
- return ASyncFuture(self.__sub(other), dependencies=self.__list_dependencies(other))
306
+ return ASyncFuture(
307
+ self.__sub(other), dependencies=self.__list_dependencies(other)
308
+ )
309
+
156
310
  def __mul__(self, other) -> "ASyncFuture":
157
- return ASyncFuture(self.__mul(other), dependencies=self.__list_dependencies(other))
311
+ return ASyncFuture(
312
+ self.__mul(other), dependencies=self.__list_dependencies(other)
313
+ )
314
+
158
315
  def __pow__(self, other) -> "ASyncFuture":
159
- return ASyncFuture(self.__pow(other), dependencies=self.__list_dependencies(other))
316
+ return ASyncFuture(
317
+ self.__pow(other), dependencies=self.__list_dependencies(other)
318
+ )
319
+
160
320
  def __truediv__(self, other) -> "ASyncFuture":
161
- return ASyncFuture(self.__truediv(other), dependencies=self.__list_dependencies(other))
321
+ return ASyncFuture(
322
+ self.__truediv(other), dependencies=self.__list_dependencies(other)
323
+ )
324
+
162
325
  def __floordiv__(self, other) -> "ASyncFuture":
163
- return ASyncFuture(self.__floordiv(other), dependencies=self.__list_dependencies(other))
326
+ return ASyncFuture(
327
+ self.__floordiv(other), dependencies=self.__list_dependencies(other)
328
+ )
329
+
164
330
  def __pow__(self, other) -> "ASyncFuture":
165
- return ASyncFuture(self.__pow(other), dependencies=self.__list_dependencies(other))
331
+ return ASyncFuture(
332
+ self.__pow(other), dependencies=self.__list_dependencies(other)
333
+ )
334
+
166
335
  @overload
167
- def __radd__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
336
+ def __radd__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
168
337
  @overload
169
- def __radd__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
338
+ def __radd__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
170
339
  @overload
171
- def __radd__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
340
+ def __radd__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
172
341
  @overload
173
- def __radd__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
342
+ def __radd__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
174
343
  @overload
175
- def __radd__(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
344
+ def __radd__(
345
+ self: "ASyncFuture[Decimal]", other: Decimal
346
+ ) -> "ASyncFuture[Decimal]": ...
176
347
  @overload
177
- def __radd__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
348
+ def __radd__(
349
+ self: "ASyncFuture[Decimal]", other: int
350
+ ) -> "ASyncFuture[Decimal]": ...
178
351
  @overload
179
- def __radd__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
352
+ def __radd__(
353
+ self: "ASyncFuture[int]", other: Decimal
354
+ ) -> "ASyncFuture[Decimal]": ...
180
355
  @overload
181
- def __radd__(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
356
+ def __radd__(
357
+ self: "ASyncFuture[int]", other: Awaitable[int]
358
+ ) -> "ASyncFuture[int]": ...
182
359
  @overload
183
- def __radd__(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
360
+ def __radd__(
361
+ self: "ASyncFuture[float]", other: Awaitable[float]
362
+ ) -> "ASyncFuture[float]": ...
184
363
  @overload
185
- def __radd__(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
364
+ def __radd__(
365
+ self: "ASyncFuture[float]", other: Awaitable[int]
366
+ ) -> "ASyncFuture[float]": ...
186
367
  @overload
187
- def __radd__(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
368
+ def __radd__(
369
+ self: "ASyncFuture[int]", other: Awaitable[float]
370
+ ) -> "ASyncFuture[float]": ...
188
371
  @overload
189
- def __radd__(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
372
+ def __radd__(
373
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
374
+ ) -> "ASyncFuture[Decimal]": ...
190
375
  @overload
191
- def __radd__(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
376
+ def __radd__(
377
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
378
+ ) -> "ASyncFuture[Decimal]": ...
192
379
  @overload
193
- def __radd__(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
380
+ def __radd__(
381
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
382
+ ) -> "ASyncFuture[Decimal]": ...
194
383
  def __radd__(self, other) -> "ASyncFuture":
195
- return ASyncFuture(self.__radd(other), dependencies=self.__list_dependencies(other))
196
-
384
+ return ASyncFuture(
385
+ self.__radd(other), dependencies=self.__list_dependencies(other)
386
+ )
387
+
197
388
  @overload
198
- def __rsub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
389
+ def __rsub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
199
390
  @overload
200
- def __rsub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
391
+ def __rsub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
201
392
  @overload
202
- def __rsub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
393
+ def __rsub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
203
394
  @overload
204
- def __rsub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
395
+ def __rsub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
205
396
  @overload
206
- def __rsub__(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
397
+ def __rsub__(
398
+ self: "ASyncFuture[Decimal]", other: Decimal
399
+ ) -> "ASyncFuture[Decimal]": ...
207
400
  @overload
208
- def __rsub__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
401
+ def __rsub__(
402
+ self: "ASyncFuture[Decimal]", other: int
403
+ ) -> "ASyncFuture[Decimal]": ...
209
404
  @overload
210
- def __rsub__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
405
+ def __rsub__(
406
+ self: "ASyncFuture[int]", other: Decimal
407
+ ) -> "ASyncFuture[Decimal]": ...
211
408
  @overload
212
- def __rsub__(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
409
+ def __rsub__(
410
+ self: "ASyncFuture[int]", other: Awaitable[int]
411
+ ) -> "ASyncFuture[int]": ...
213
412
  @overload
214
- def __rsub__(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
413
+ def __rsub__(
414
+ self: "ASyncFuture[float]", other: Awaitable[float]
415
+ ) -> "ASyncFuture[float]": ...
215
416
  @overload
216
- def __rsub__(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
417
+ def __rsub__(
418
+ self: "ASyncFuture[float]", other: Awaitable[int]
419
+ ) -> "ASyncFuture[float]": ...
217
420
  @overload
218
- def __rsub__(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
421
+ def __rsub__(
422
+ self: "ASyncFuture[int]", other: Awaitable[float]
423
+ ) -> "ASyncFuture[float]": ...
219
424
  @overload
220
- def __rsub__(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
425
+ def __rsub__(
426
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
427
+ ) -> "ASyncFuture[Decimal]": ...
221
428
  @overload
222
- def __rsub__(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
429
+ def __rsub__(
430
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
431
+ ) -> "ASyncFuture[Decimal]": ...
223
432
  @overload
224
- def __rsub__(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
433
+ def __rsub__(
434
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
435
+ ) -> "ASyncFuture[Decimal]": ...
225
436
  def __rsub__(self, other) -> "ASyncFuture":
226
- return ASyncFuture(self.__rsub(other), dependencies=self.__list_dependencies(other))
437
+ return ASyncFuture(
438
+ self.__rsub(other), dependencies=self.__list_dependencies(other)
439
+ )
440
+
227
441
  def __rmul__(self, other) -> "ASyncFuture":
228
- return ASyncFuture(self.__rmul(other), dependencies=self.__list_dependencies(other))
442
+ return ASyncFuture(
443
+ self.__rmul(other), dependencies=self.__list_dependencies(other)
444
+ )
445
+
229
446
  def __rtruediv__(self, other) -> "ASyncFuture":
230
- return ASyncFuture(self.__rtruediv(other), dependencies=self.__list_dependencies(other))
447
+ return ASyncFuture(
448
+ self.__rtruediv(other), dependencies=self.__list_dependencies(other)
449
+ )
450
+
231
451
  def __rfloordiv__(self, other) -> "ASyncFuture":
232
- return ASyncFuture(self.__rfloordiv(other), dependencies=self.__list_dependencies(other))
452
+ return ASyncFuture(
453
+ self.__rfloordiv(other), dependencies=self.__list_dependencies(other)
454
+ )
455
+
233
456
  def __rpow__(self, other) -> "ASyncFuture":
234
- return ASyncFuture(self.__rpow(other), dependencies=self.__list_dependencies(other))
457
+ return ASyncFuture(
458
+ self.__rpow(other), dependencies=self.__list_dependencies(other)
459
+ )
460
+
235
461
  def __eq__(self, other) -> "ASyncFuture":
236
- return bool(ASyncFuture(self.__eq(other), dependencies=self.__list_dependencies(other)))
462
+ return bool(
463
+ ASyncFuture(self.__eq(other), dependencies=self.__list_dependencies(other))
464
+ )
465
+
237
466
  def __gt__(self, other) -> "ASyncFuture":
238
- return ASyncFuture(self.__gt(other), dependencies=self.__list_dependencies(other))
467
+ return ASyncFuture(
468
+ self.__gt(other), dependencies=self.__list_dependencies(other)
469
+ )
470
+
239
471
  def __ge__(self, other) -> "ASyncFuture":
240
- return ASyncFuture(self.__ge(other), dependencies=self.__list_dependencies(other))
472
+ return ASyncFuture(
473
+ self.__ge(other), dependencies=self.__list_dependencies(other)
474
+ )
475
+
241
476
  def __lt__(self, other) -> "ASyncFuture":
242
- return ASyncFuture(self.__lt(other), dependencies=self.__list_dependencies(other))
477
+ return ASyncFuture(
478
+ self.__lt(other), dependencies=self.__list_dependencies(other)
479
+ )
480
+
243
481
  def __le__(self, other) -> "ASyncFuture":
244
- return ASyncFuture(self.__le(other), dependencies=self.__list_dependencies(other))
245
-
482
+ return ASyncFuture(
483
+ self.__le(other), dependencies=self.__list_dependencies(other)
484
+ )
485
+
246
486
  # Maths
247
-
487
+
248
488
  @overload
249
- async def __add(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
489
+ async def __add(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
250
490
  @overload
251
- async def __add(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
491
+ async def __add(
492
+ self: "ASyncFuture[float]", other: float
493
+ ) -> "ASyncFuture[float]": ...
252
494
  @overload
253
- async def __add(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
495
+ async def __add(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
254
496
  @overload
255
- async def __add(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
497
+ async def __add(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
256
498
  @overload
257
- async def __add(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
499
+ async def __add(
500
+ self: "ASyncFuture[Decimal]", other: Decimal
501
+ ) -> "ASyncFuture[Decimal]": ...
258
502
  @overload
259
- async def __add(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
503
+ async def __add(
504
+ self: "ASyncFuture[Decimal]", other: int
505
+ ) -> "ASyncFuture[Decimal]": ...
260
506
  @overload
261
- async def __add(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
507
+ async def __add(
508
+ self: "ASyncFuture[int]", other: Decimal
509
+ ) -> "ASyncFuture[Decimal]": ...
262
510
  @overload
263
- async def __add(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
511
+ async def __add(
512
+ self: "ASyncFuture[int]", other: Awaitable[int]
513
+ ) -> "ASyncFuture[int]": ...
264
514
  @overload
265
- async def __add(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
515
+ async def __add(
516
+ self: "ASyncFuture[float]", other: Awaitable[float]
517
+ ) -> "ASyncFuture[float]": ...
266
518
  @overload
267
- async def __add(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
519
+ async def __add(
520
+ self: "ASyncFuture[float]", other: Awaitable[int]
521
+ ) -> "ASyncFuture[float]": ...
268
522
  @overload
269
- async def __add(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
523
+ async def __add(
524
+ self: "ASyncFuture[int]", other: Awaitable[float]
525
+ ) -> "ASyncFuture[float]": ...
270
526
  @overload
271
- async def __add(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
527
+ async def __add(
528
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
529
+ ) -> "ASyncFuture[Decimal]": ...
272
530
  @overload
273
- async def __add(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
531
+ async def __add(
532
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
533
+ ) -> "ASyncFuture[Decimal]": ...
274
534
  @overload
275
- async def __add(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
535
+ async def __add(
536
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
537
+ ) -> "ASyncFuture[Decimal]": ...
276
538
  async def __add(self, other) -> "Any":
277
539
  a, b = await _gather_check_and_materialize(self, other)
278
540
  return a + b
541
+
279
542
  @overload
280
- async def __sub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
543
+ async def __sub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
281
544
  @overload
282
- async def __sub(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
545
+ async def __sub(
546
+ self: "ASyncFuture[float]", other: float
547
+ ) -> "ASyncFuture[float]": ...
283
548
  @overload
284
- async def __sub(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
549
+ async def __sub(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
285
550
  @overload
286
- async def __sub(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
551
+ async def __sub(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
287
552
  @overload
288
- async def __sub(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
553
+ async def __sub(
554
+ self: "ASyncFuture[Decimal]", other: Decimal
555
+ ) -> "ASyncFuture[Decimal]": ...
289
556
  @overload
290
- async def __sub(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
557
+ async def __sub(
558
+ self: "ASyncFuture[Decimal]", other: int
559
+ ) -> "ASyncFuture[Decimal]": ...
291
560
  @overload
292
- async def __sub(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
561
+ async def __sub(
562
+ self: "ASyncFuture[int]", other: Decimal
563
+ ) -> "ASyncFuture[Decimal]": ...
293
564
  @overload
294
- async def __sub(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
565
+ async def __sub(
566
+ self: "ASyncFuture[int]", other: Awaitable[int]
567
+ ) -> "ASyncFuture[int]": ...
295
568
  @overload
296
- async def __sub(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
569
+ async def __sub(
570
+ self: "ASyncFuture[float]", other: Awaitable[float]
571
+ ) -> "ASyncFuture[float]": ...
297
572
  @overload
298
- async def __sub(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
573
+ async def __sub(
574
+ self: "ASyncFuture[float]", other: Awaitable[int]
575
+ ) -> "ASyncFuture[float]": ...
299
576
  @overload
300
- async def __sub(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
577
+ async def __sub(
578
+ self: "ASyncFuture[int]", other: Awaitable[float]
579
+ ) -> "ASyncFuture[float]": ...
301
580
  @overload
302
- async def __sub(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
581
+ async def __sub(
582
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
583
+ ) -> "ASyncFuture[Decimal]": ...
303
584
  @overload
304
- async def __sub(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
585
+ async def __sub(
586
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
587
+ ) -> "ASyncFuture[Decimal]": ...
305
588
  @overload
306
- async def __sub(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
589
+ async def __sub(
590
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
591
+ ) -> "ASyncFuture[Decimal]": ...
307
592
  async def __sub(self, other) -> "Any":
308
593
  a, b = await _gather_check_and_materialize(self, other)
309
594
  return a - b
595
+
310
596
  async def __mul(self, other) -> "Any":
311
597
  a, b = await _gather_check_and_materialize(self, other)
312
598
  return a * b
599
+
313
600
  async def __truediv(self, other) -> "Any":
314
601
  a, b = await _gather_check_and_materialize(self, other)
315
602
  return a / b
603
+
316
604
  async def __floordiv(self, other) -> "Any":
317
605
  a, b = await _gather_check_and_materialize(self, other)
318
606
  return a // b
607
+
319
608
  async def __pow(self, other) -> "Any":
320
609
  a, b = await _gather_check_and_materialize(self, other)
321
- return a ** b
322
-
610
+ return a**b
611
+
323
612
  # rMaths
324
613
  @overload
325
- async def __radd(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
614
+ async def __radd(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
326
615
  @overload
327
- async def __radd(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
616
+ async def __radd(
617
+ self: "ASyncFuture[float]", other: float
618
+ ) -> "ASyncFuture[float]": ...
328
619
  @overload
329
- async def __radd(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
620
+ async def __radd(
621
+ self: "ASyncFuture[float]", other: int
622
+ ) -> "ASyncFuture[float]": ...
330
623
  @overload
331
- async def __radd(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
624
+ async def __radd(
625
+ self: "ASyncFuture[int]", other: float
626
+ ) -> "ASyncFuture[float]": ...
332
627
  @overload
333
- async def __radd(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
628
+ async def __radd(
629
+ self: "ASyncFuture[Decimal]", other: Decimal
630
+ ) -> "ASyncFuture[Decimal]": ...
334
631
  @overload
335
- async def __radd(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
632
+ async def __radd(
633
+ self: "ASyncFuture[Decimal]", other: int
634
+ ) -> "ASyncFuture[Decimal]": ...
336
635
  @overload
337
- async def __radd(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
636
+ async def __radd(
637
+ self: "ASyncFuture[int]", other: Decimal
638
+ ) -> "ASyncFuture[Decimal]": ...
338
639
  @overload
339
- async def __radd(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
640
+ async def __radd(
641
+ self: "ASyncFuture[int]", other: Awaitable[int]
642
+ ) -> "ASyncFuture[int]": ...
340
643
  @overload
341
- async def __radd(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
644
+ async def __radd(
645
+ self: "ASyncFuture[float]", other: Awaitable[float]
646
+ ) -> "ASyncFuture[float]": ...
342
647
  @overload
343
- async def __radd(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
648
+ async def __radd(
649
+ self: "ASyncFuture[float]", other: Awaitable[int]
650
+ ) -> "ASyncFuture[float]": ...
344
651
  @overload
345
- async def __radd(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
652
+ async def __radd(
653
+ self: "ASyncFuture[int]", other: Awaitable[float]
654
+ ) -> "ASyncFuture[float]": ...
346
655
  @overload
347
- async def __radd(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
656
+ async def __radd(
657
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
658
+ ) -> "ASyncFuture[Decimal]": ...
348
659
  @overload
349
- async def __radd(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
660
+ async def __radd(
661
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
662
+ ) -> "ASyncFuture[Decimal]": ...
350
663
  @overload
351
- async def __radd(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
664
+ async def __radd(
665
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
666
+ ) -> "ASyncFuture[Decimal]": ...
352
667
  async def __radd(self, other) -> "Any":
353
668
  a, b = await _gather_check_and_materialize(other, self)
354
669
  return a + b
670
+
355
671
  @overload
356
- async def __rsub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
672
+ async def __rsub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
357
673
  @overload
358
- async def __rsub(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
674
+ async def __rsub(
675
+ self: "ASyncFuture[float]", other: float
676
+ ) -> "ASyncFuture[float]": ...
359
677
  @overload
360
- async def __rsub(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
678
+ async def __rsub(
679
+ self: "ASyncFuture[float]", other: int
680
+ ) -> "ASyncFuture[float]": ...
361
681
  @overload
362
- async def __rsub(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
682
+ async def __rsub(
683
+ self: "ASyncFuture[int]", other: float
684
+ ) -> "ASyncFuture[float]": ...
363
685
  @overload
364
- async def __rsub(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
686
+ async def __rsub(
687
+ self: "ASyncFuture[Decimal]", other: Decimal
688
+ ) -> "ASyncFuture[Decimal]": ...
365
689
  @overload
366
- async def __rsub(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
690
+ async def __rsub(
691
+ self: "ASyncFuture[Decimal]", other: int
692
+ ) -> "ASyncFuture[Decimal]": ...
367
693
  @overload
368
- async def __rsub(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
694
+ async def __rsub(
695
+ self: "ASyncFuture[int]", other: Decimal
696
+ ) -> "ASyncFuture[Decimal]": ...
369
697
  @overload
370
- async def __rsub(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
698
+ async def __rsub(
699
+ self: "ASyncFuture[int]", other: Awaitable[int]
700
+ ) -> "ASyncFuture[int]": ...
371
701
  @overload
372
- async def __rsub(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
702
+ async def __rsub(
703
+ self: "ASyncFuture[float]", other: Awaitable[float]
704
+ ) -> "ASyncFuture[float]": ...
373
705
  @overload
374
- async def __rsub(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
706
+ async def __rsub(
707
+ self: "ASyncFuture[float]", other: Awaitable[int]
708
+ ) -> "ASyncFuture[float]": ...
375
709
  @overload
376
- async def __rsub(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
710
+ async def __rsub(
711
+ self: "ASyncFuture[int]", other: Awaitable[float]
712
+ ) -> "ASyncFuture[float]": ...
377
713
  @overload
378
- async def __rsub(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
714
+ async def __rsub(
715
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
716
+ ) -> "ASyncFuture[Decimal]": ...
379
717
  @overload
380
- async def __rsub(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
718
+ async def __rsub(
719
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
720
+ ) -> "ASyncFuture[Decimal]": ...
381
721
  @overload
382
- async def __rsub(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
722
+ async def __rsub(
723
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
724
+ ) -> "ASyncFuture[Decimal]": ...
383
725
  async def __rsub(self, other) -> "Any":
384
726
  a, b = await _gather_check_and_materialize(other, self)
385
727
  return a - b
728
+
386
729
  async def __rmul(self, other) -> "Any":
387
730
  a, b = await _gather_check_and_materialize(other, self)
388
731
  return a * b
732
+
389
733
  async def __rtruediv(self, other) -> "Any":
390
734
  a, b = await _gather_check_and_materialize(other, self)
391
735
  return a / b
736
+
392
737
  async def __rfloordiv(self, other) -> "Any":
393
738
  a, b = await _gather_check_and_materialize(other, self)
394
739
  return a // b
740
+
395
741
  async def __rpow(self, other) -> "Any":
396
742
  a, b = await _gather_check_and_materialize(other, self)
397
- return a ** b
398
-
743
+ return a**b
744
+
399
745
  async def __iadd(self, other) -> "Any":
400
746
  a, b = await _gather_check_and_materialize(self, other)
401
747
  self._result = a + b
402
748
  return self._result
749
+
403
750
  async def __isub(self, other) -> "Any":
404
751
  a, b = await _gather_check_and_materialize(self, other)
405
752
  self._result = a - b
406
753
  return self._result
754
+
407
755
  async def __imul(self, other) -> "Any":
408
756
  a, b = await _gather_check_and_materialize(self, other)
409
757
  self._result = a * b
410
758
  return self._result
759
+
411
760
  async def __itruediv(self, other) -> "Any":
412
761
  a, b = await _gather_check_and_materialize(self, other)
413
762
  self._result = a / b
414
763
  return self._result
764
+
415
765
  async def __ifloordiv(self, other) -> "Any":
416
766
  a, b = await _gather_check_and_materialize(self, other)
417
767
  self._result = a // b
418
768
  return self._result
769
+
419
770
  async def __ipow(self, other) -> "Any":
420
771
  a, b = await _gather_check_and_materialize(self, other)
421
- self._result = a ** b
772
+ self._result = a**b
422
773
  return self._result
423
-
774
+
424
775
  # Comparisons
425
776
  async def __eq(self, other) -> bool:
426
777
  a, b = await _gather_check_and_materialize(self, other)
427
778
  return a == b
779
+
428
780
  async def __gt(self, other) -> bool:
429
781
  a, b = await _gather_check_and_materialize(self, other)
430
782
  return a > b
783
+
431
784
  async def __ge(self, other) -> bool:
432
785
  a, b = await _gather_check_and_materialize(self, other)
433
786
  return a >= b
787
+
434
788
  async def __lt(self, other) -> bool:
435
789
  a, b = await _gather_check_and_materialize(self, other)
436
790
  return a < b
791
+
437
792
  async def __le(self, other) -> bool:
438
793
  a, b = await _gather_check_and_materialize(self, other)
439
794
  return a <= b
440
795
 
441
-
442
796
  # not sure what to call these
443
797
  async def __contains(self, item: Any) -> bool:
444
798
  _self, _item = await _gather_check_and_materialize(self, item)
445
799
  return _item in _self
446
-
800
+
447
801
  # conversion
448
802
  # NOTE: We aren't allowed to return ASyncFutures here :(
449
803
  def __bool__(self) -> bool:
450
804
  return bool(_materialize(self))
805
+
451
806
  def __bytes__(self) -> bytes:
452
807
  return bytes(_materialize(self))
808
+
453
809
  def __str__(self) -> str:
454
810
  return str(_materialize(self))
811
+
455
812
  def __int__(self) -> int:
456
813
  return int(_materialize(self))
814
+
457
815
  def __float__(self) -> float:
458
816
  return float(_materialize(self))
459
-
817
+
460
818
  # WIP internals
461
-
819
+
462
820
  @property
463
821
  def __dependants__(self) -> Set["ASyncFuture"]:
822
+ """
823
+ Returns the set of dependants for this ASyncFuture, including nested dependants.
824
+ """
464
825
  dependants = set()
465
826
  for dep in self.__dependants:
466
827
  dependants.add(dep)
467
828
  dependants.union(dep.__dependants__)
468
829
  return dependants
830
+
469
831
  @property
470
832
  def __dependencies__(self) -> Set["ASyncFuture"]:
833
+ """
834
+ Returns the set of dependencies for this ASyncFuture, including nested dependencies.
835
+ """
471
836
  dependencies = set()
472
837
  for dep in self.__dependencies:
473
838
  dependencies.add(dep)
474
839
  dependencies.union(dep.__dependencies__)
475
840
  return dependencies
841
+
476
842
  def __sizeof__(self) -> int:
477
843
  if isinstance(self.__awaitable__, Coroutine):
478
- return sum(sys.getsizeof(v) for v in self.__awaitable__.cr_frame.f_locals.values())
844
+ return sum(
845
+ sys.getsizeof(v) for v in self.__awaitable__.cr_frame.f_locals.values()
846
+ )
479
847
  elif isinstance(self.__awaitable__, asyncio.Future):
480
848
  raise NotImplementedError
481
849
  raise NotImplementedError
482
850
 
483
851
 
484
- @final
852
+ @final
485
853
  class _ASyncFutureWrappedFn(Callable[P, ASyncFuture[T]]):
854
+ """
855
+ A callable class to wrap functions and return ASyncFuture objects.
856
+ """
857
+
486
858
  __slots__ = "callable", "wrapped", "_callable_name"
487
- def __init__(self, callable: Union[Callable[P, Awaitable[T]], Callable[P, T]] = None, **kwargs: Unpack[ModifierKwargs]):
859
+
860
+ def __init__(
861
+ self,
862
+ callable: AnyFn[P, T] = None,
863
+ **kwargs: Unpack[ModifierKwargs],
864
+ ):
488
865
  from a_sync import a_sync
866
+
489
867
  if callable:
490
868
  self.callable = callable
869
+ """The callable function."""
870
+
491
871
  self._callable_name = callable.__name__
872
+ """The name of the callable function."""
873
+
492
874
  a_sync_callable = a_sync(callable, default="async", **kwargs)
875
+
493
876
  @wraps(callable)
494
877
  def future_wrap(*args: P.args, **kwargs: P.kwargs) -> "ASyncFuture[T]":
495
878
  return ASyncFuture(a_sync_callable(*args, **kwargs, sync=False))
879
+
496
880
  self.wrapped = future_wrap
881
+ """The wrapped function returning ASyncFuture."""
497
882
  else:
498
883
  self.wrapped = partial(_ASyncFutureWrappedFn, **kwargs)
884
+
499
885
  def __call__(self, *args: P.args, **kwargs: P.kwargs) -> ASyncFuture[T]:
500
886
  return self.wrapped(*args, **kwargs)
887
+
501
888
  def __repr__(self) -> str:
502
889
  return f"<{self.__class__.__name__} {self.callable}>"
503
- def __get__(self, instance: I, owner: Type[I]) -> Union[Self, "_ASyncFutureInstanceMethod[I, P, T]"]:
890
+
891
+ def __get__(
892
+ self, instance: I, owner: Type[I]
893
+ ) -> Union[Self, "_ASyncFutureInstanceMethod[I, P, T]"]:
504
894
  if owner is None:
505
895
  return self
506
896
  else:
507
897
  return _ASyncFutureInstanceMethod(self, instance)
508
898
 
899
+
509
900
  @final
510
901
  class _ASyncFutureInstanceMethod(Generic[I, P, T]):
511
902
  # NOTE: probably could just replace this with functools.partial
903
+ """
904
+ A class to handle instance methods wrapped as ASyncFuture.
905
+ """
906
+
907
+ __module__: str
908
+ """The module name of the wrapper."""
909
+
910
+ __name__: str
911
+ """The name of the wrapper."""
912
+
913
+ __qualname__: str
914
+ """The qualified name of the wrapper."""
915
+
916
+ __doc__: Optional[str]
917
+ """The docstring of the wrapper."""
918
+
919
+ __annotations__: Dict[str, Any]
920
+ """The annotations of the wrapper."""
921
+
922
+ __instance: I
923
+ """The instance to which the method is bound."""
924
+
925
+ __wrapper: _ASyncFutureWrappedFn[P, T]
926
+ """The wrapper function."""
927
+
512
928
  def __init__(
513
929
  self,
514
930
  wrapper: _ASyncFutureWrappedFn[P, T],
@@ -543,6 +959,7 @@ class _ASyncFutureInstanceMethod(Generic[I, P, T]):
543
959
 
544
960
  def __repr__(self) -> str:
545
961
  return f"<{self.__class__.__name__} for {self.__wrapper.callable} bound to {self.__instance}>"
962
+
546
963
  def __call__(self, /, *fn_args: P.args, **fn_kwargs: P.kwargs) -> T:
547
964
  return self.__wrapper(self.__instance, *fn_args, **fn_kwargs)
548
965