ez-a-sync 0.22.14__py3-none-any.whl → 0.22.16__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 +37 -5
  2. a_sync/__init__.py +53 -12
  3. a_sync/_smart.py +231 -28
  4. a_sync/_typing.py +112 -15
  5. a_sync/a_sync/__init__.py +35 -10
  6. a_sync/a_sync/_descriptor.py +248 -38
  7. a_sync/a_sync/_flags.py +78 -9
  8. a_sync/a_sync/_helpers.py +46 -13
  9. a_sync/a_sync/_kwargs.py +33 -8
  10. a_sync/a_sync/_meta.py +149 -28
  11. a_sync/a_sync/abstract.py +150 -28
  12. a_sync/a_sync/base.py +34 -16
  13. a_sync/a_sync/config.py +85 -14
  14. a_sync/a_sync/decorator.py +441 -139
  15. a_sync/a_sync/function.py +709 -147
  16. a_sync/a_sync/method.py +437 -110
  17. a_sync/a_sync/modifiers/__init__.py +85 -5
  18. a_sync/a_sync/modifiers/cache/__init__.py +116 -17
  19. a_sync/a_sync/modifiers/cache/memory.py +130 -20
  20. a_sync/a_sync/modifiers/limiter.py +101 -22
  21. a_sync/a_sync/modifiers/manager.py +142 -16
  22. a_sync/a_sync/modifiers/semaphores.py +121 -15
  23. a_sync/a_sync/property.py +383 -82
  24. a_sync/a_sync/singleton.py +44 -19
  25. a_sync/aliases.py +0 -1
  26. a_sync/asyncio/__init__.py +140 -1
  27. a_sync/asyncio/as_completed.py +213 -79
  28. a_sync/asyncio/create_task.py +70 -20
  29. a_sync/asyncio/gather.py +125 -58
  30. a_sync/asyncio/utils.py +3 -3
  31. a_sync/exceptions.py +248 -26
  32. a_sync/executor.py +164 -69
  33. a_sync/future.py +1227 -168
  34. a_sync/iter.py +173 -56
  35. a_sync/primitives/__init__.py +14 -2
  36. a_sync/primitives/_debug.py +72 -18
  37. a_sync/primitives/_loggable.py +41 -10
  38. a_sync/primitives/locks/__init__.py +5 -2
  39. a_sync/primitives/locks/counter.py +107 -38
  40. a_sync/primitives/locks/event.py +21 -7
  41. a_sync/primitives/locks/prio_semaphore.py +262 -63
  42. a_sync/primitives/locks/semaphore.py +138 -89
  43. a_sync/primitives/queue.py +601 -60
  44. a_sync/sphinx/__init__.py +0 -1
  45. a_sync/sphinx/ext.py +160 -50
  46. a_sync/task.py +313 -112
  47. a_sync/utils/__init__.py +12 -6
  48. a_sync/utils/iterators.py +170 -50
  49. {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.16.dist-info}/METADATA +1 -1
  50. ez_a_sync-0.22.16.dist-info/RECORD +74 -0
  51. {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.16.dist-info}/WHEEL +1 -1
  52. tests/conftest.py +1 -2
  53. tests/executor.py +250 -9
  54. tests/fixtures.py +61 -32
  55. tests/test_abstract.py +22 -4
  56. tests/test_as_completed.py +54 -21
  57. tests/test_base.py +264 -19
  58. tests/test_cache.py +31 -15
  59. tests/test_decorator.py +54 -28
  60. tests/test_executor.py +31 -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 +28 -11
  70. tests/test_task.py +162 -36
  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.16.dist-info}/LICENSE.txt +0 -0
  73. {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.16.dist-info}/top_level.txt +0 -0
a_sync/future.py CHANGED
@@ -1,5 +1,30 @@
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
+
21
+ TODO include a simple mathematics example a one complex example with numerous variables and operations
22
+ TODO include attribute access examples
23
+ TODO describe a bit more about both of the above 2 TODOs somewhere in this module-level docstring
24
+ TODO describe why a user would want to use these (to write cleaner code that doesn't require as many ugly gathers)
25
+ TODO include comparisons between the 'new way' with this future class and the 'old way' with gathers
26
+ """
27
+
3
28
  import asyncio
4
29
  import concurrent.futures
5
30
  from functools import partial, wraps
@@ -8,512 +33,1545 @@ from inspect import isawaitable
8
33
  from a_sync._typing import *
9
34
 
10
35
 
11
- def future(callable: Union[Callable[P, Awaitable[T]], Callable[P, T]] = None, **kwargs: Unpack[ModifierKwargs]) -> Callable[P, Union[T, "ASyncFuture[T]"]]:
36
+ def future(
37
+ callable: AnyFn[P, T] = None,
38
+ **kwargs: Unpack[ModifierKwargs],
39
+ ) -> Callable[P, Union[T, "ASyncFuture[T]"]]:
40
+ """
41
+ A decorator function to convert a callable into an `ASyncFuture`, with optional modifiers.
42
+
43
+ This function wraps the provided callable in an `_ASyncFutureWrappedFn` instance,
44
+ which returns an `ASyncFuture` when called. The `ASyncFuture` allows the result
45
+ of the callable to be awaited or accessed synchronously.
46
+
47
+ Args:
48
+ callable: The callable to convert. Defaults to None.
49
+ **kwargs: Additional keyword arguments for the modifier.
50
+
51
+ Returns:
52
+ A callable that returns either the result or an `ASyncFuture`.
53
+
54
+ Example:
55
+ >>> @future
56
+ ... async def async_function():
57
+ ... return 42
58
+ >>> result = async_function()
59
+ >>> isinstance(result, ASyncFuture)
60
+ True
61
+
62
+ See Also:
63
+ :class:`ASyncFuture`
64
+ """
12
65
  return _ASyncFutureWrappedFn(callable, **kwargs)
13
66
 
67
+
14
68
  async def _gather_check_and_materialize(*things: Unpack[MaybeAwaitable[T]]) -> List[T]:
69
+ """
70
+ Gathers and materializes a list of awaitable or non-awaitable items.
71
+
72
+ This function takes a list of items that may be awaitable or not, and
73
+ returns a list of their results. Awaitable items are awaited, while
74
+ non-awaitable items are returned as-is.
75
+
76
+ Args:
77
+ *things: Items to gather and materialize.
78
+
79
+ Example:
80
+ >>> async def async_fn(x):
81
+ ... return x
82
+ >>> await _gather_check_and_materialize(async_fn(1), 2, async_fn(3))
83
+ [1, 2, 3]
84
+ """
15
85
  return await asyncio.gather(*[_check_and_materialize(thing) for thing in things])
16
86
 
87
+
17
88
  async def _check_and_materialize(thing: T) -> T:
89
+ """
90
+ Checks if an item is awaitable and materializes it.
91
+
92
+ If the item is awaitable, it is awaited and the result is returned.
93
+ Otherwise, the item is returned as-is.
94
+
95
+ Args:
96
+ thing: The item to check and materialize.
97
+
98
+ Example:
99
+ >>> async def async_fn():
100
+ ... return 42
101
+ >>> await _check_and_materialize(async_fn())
102
+ 42
103
+ """
18
104
  return await thing if isawaitable(thing) else thing
19
-
105
+
106
+
20
107
  def _materialize(meta: "ASyncFuture[T]") -> T:
108
+ """
109
+ Materializes the result of an `ASyncFuture`.
110
+
111
+ This function attempts to run the event loop until the `ASyncFuture` is complete.
112
+ If the event loop is already running, it raises a RuntimeError.
113
+
114
+ Args:
115
+ meta: The `ASyncFuture` to materialize.
116
+
117
+ Raises:
118
+ RuntimeError: If the event loop is running and the result cannot be awaited.
119
+
120
+ Example:
121
+ >>> future = ASyncFuture(asyncio.sleep(1, result=42))
122
+ >>> _materialize(future)
123
+ 42
124
+
125
+ See Also:
126
+ :class:`ASyncFuture`
127
+ """
21
128
  try:
22
129
  return asyncio.get_event_loop().run_until_complete(meta)
23
130
  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
131
+ raise RuntimeError(
132
+ f"{meta} result is not set and the event loop is running, you will need to await it first"
133
+ ) from e
134
+
25
135
 
26
- MetaNumeric = Union[Numeric, "ASyncFuture[int]", "ASyncFuture[float]", "ASyncFuture[Decimal]"]
136
+ MetaNumeric = Union[
137
+ Numeric, "ASyncFuture[int]", "ASyncFuture[float]", "ASyncFuture[Decimal]"
138
+ ]
27
139
 
140
+
141
+ @final
28
142
  class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
143
+ """
144
+ A class representing an asynchronous future result.
145
+
146
+ Inherits from both `concurrent.futures.Future` and `Awaitable[T]`, allowing it to be used in both synchronous and asynchronous contexts.
147
+
148
+ The `ASyncFuture` class provides additional functionality for arithmetic operations,
149
+ comparisons, and conversions, making it versatile for various use cases.
150
+
151
+ Example:
152
+ >>> async def async_fn():
153
+ ... return 42
154
+ >>> future = ASyncFuture(async_fn())
155
+ >>> await future
156
+ 42
157
+
158
+ Note:
159
+ Some arithmetic operations are currently broken or incomplete. Use with caution.
160
+
161
+ TODO include a simple mathematics example a one complex example with numerous variables and operations
162
+ TODO include attribute access examples
163
+ TODO describe a bit more about both of the above 2 TODOs somewhere in this class-level docstring
164
+ TODO describe why a user would want to use these (to write cleaner code that doesn't require as many ugly gathers)
165
+ TODO include comparisons between the 'new way' with this future class and the 'old way' with gathers
166
+ """
167
+
29
168
  __slots__ = "__awaitable__", "__dependencies", "__dependants", "__task"
30
-
31
- def __init__(self, awaitable: Awaitable[T], dependencies: List["ASyncFuture"] = []) -> None:
169
+
170
+ def __init__(
171
+ self, awaitable: Awaitable[T], dependencies: List["ASyncFuture"] = []
172
+ ) -> None: # sourcery skip: default-mutable-arg
173
+ """
174
+ Initializes an `ASyncFuture` with an awaitable and optional dependencies.
175
+
176
+ Args:
177
+ awaitable: The awaitable object.
178
+ dependencies: A list of dependencies. Defaults to [].
179
+
180
+ Example:
181
+ >>> async def async_fn():
182
+ ... return 42
183
+ >>> future = ASyncFuture(async_fn())
184
+ >>> await future
185
+ 42
186
+ """
187
+
32
188
  self.__awaitable__ = awaitable
189
+ """The awaitable object."""
190
+
33
191
  self.__dependencies = dependencies
192
+ """A list of dependencies."""
193
+
34
194
  for dependency in dependencies:
35
195
  assert isinstance(dependency, ASyncFuture)
36
196
  dependency.__dependants.append(self)
197
+
37
198
  self.__dependants: List[ASyncFuture] = []
199
+ """A list of dependants."""
200
+
38
201
  self.__task = None
202
+ """The task associated with the awaitable."""
203
+
39
204
  super().__init__()
205
+
40
206
  def __hash__(self) -> int:
41
207
  return hash(self.__awaitable__)
208
+
42
209
  def __repr__(self) -> str:
43
210
  string = f"<{self.__class__.__name__} {self._state} for {self.__awaitable__}"
44
211
  if self.cancelled():
45
212
  pass
46
213
  elif self.done():
47
- string += f" exception={self.exception()}" if self.exception() else f" result={super().result()}"
48
- return string + ">"
214
+ string += (
215
+ f" exception={self.exception()}"
216
+ if self.exception()
217
+ else f" result={super().result()}"
218
+ )
219
+ return f"{string}>"
220
+
49
221
  def __list_dependencies(self, other) -> List["ASyncFuture"]:
50
- if isinstance(other, ASyncFuture):
51
- return [self, other]
52
- return [self]
222
+ """
223
+ Lists dependencies for the `ASyncFuture`.
224
+
225
+ Args:
226
+ other: The other dependency to list.
227
+
228
+ Returns:
229
+ A list of dependencies including the current and other `ASyncFuture`.
230
+ """
231
+ return [self, other] if isinstance(other, ASyncFuture) else [self]
232
+
53
233
  @property
54
234
  def result(self) -> Union[Callable[[], T], Any]:
235
+ # sourcery skip: assign-if-exp, reintroduce-else
55
236
  """
56
- 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
237
+ 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.
238
+ If this future is done and the result has attribute `result`, will return `getattr(future_result, 'result')`
239
+ If this future is done and the result does NOT have attribute `result`, will again work like `cf.Future.result`
240
+
241
+ Example:
242
+ >>> future = ASyncFuture(asyncio.sleep(1, result=42))
243
+ >>> future.result()
244
+ 42
59
245
  """
60
246
  if self.done():
61
- if hasattr(r := super().result(), 'result'):
247
+ if hasattr(r := super().result(), "result"):
62
248
  # can be property, method, whatever. should work.
63
249
  return r.result
64
250
  # the result should be callable like an asyncio.Future
65
251
  return super().result
66
252
  return lambda: _materialize(self)
253
+
67
254
  def __getattr__(self, attr: str) -> Any:
255
+ """
256
+ Allows access to attributes of the materialized result.
257
+
258
+ Args:
259
+ attr: The attribute name to access.
260
+
261
+ Returns:
262
+ The attribute value from the materialized result.
263
+
264
+ Example:
265
+ >>> class Example:
266
+ ... def __init__(self, value):
267
+ ... self.value = value
268
+ >>> future = ASyncFuture(asyncio.sleep(1, result=Example(42)))
269
+ >>> future.value
270
+ 42
271
+ """
68
272
  return getattr(_materialize(self), attr)
273
+
69
274
  def __getitem__(self, key) -> Any:
275
+ """
276
+ Allows item access on the materialized result.
277
+
278
+ Args:
279
+ key: The key to access.
280
+
281
+ Returns:
282
+ The item from the materialized result.
283
+
284
+ Example:
285
+ >>> future = ASyncFuture(asyncio.sleep(1, result={'key': 'value'}))
286
+ >>> future['key']
287
+ 'value'
288
+ """
70
289
  return _materialize(self)[key]
290
+
71
291
  # NOTE: broken, do not use. I think
72
292
  def __setitem__(self, key, value) -> None:
293
+ """
294
+ Allows setting an item on the materialized result.
295
+
296
+ Args:
297
+ key: The key to set.
298
+ value: The value to set.
299
+
300
+ Example:
301
+ >>> future = ASyncFuture(asyncio.sleep(1, result={'key': 'value'}))
302
+ >>> future['key'] = 'new_value'
303
+ """
73
304
  _materialize(self)[key] = value
305
+
74
306
  # not sure what to call these
75
307
  def __contains__(self, key: Any) -> bool:
76
- return _materialize(ASyncFuture(self.__contains(key), dependencies=self.__list_dependencies(key)))
308
+ """
309
+ Checks if a key is in the materialized result.
310
+
311
+ Args:
312
+ key: The key to check.
313
+
314
+ Returns:
315
+ True if the key is in the materialized result, False otherwise.
316
+
317
+ Example:
318
+ >>> future = ASyncFuture(asyncio.sleep(1, result={'key': 'value'}))
319
+ >>> 'key' in future
320
+ True
321
+ """
322
+ return _materialize(
323
+ ASyncFuture(
324
+ self.__contains(key), dependencies=self.__list_dependencies(key)
325
+ )
326
+ )
327
+
77
328
  def __await__(self) -> Generator[Any, None, T]:
329
+ """
330
+ Makes the `ASyncFuture` awaitable.
331
+
332
+ Example:
333
+ >>> future = ASyncFuture(asyncio.sleep(1, result=42))
334
+ >>> await future
335
+ 42
336
+ """
78
337
  return self.__await().__await__()
338
+
79
339
  async def __await(self) -> T:
80
340
  if not self.done():
81
341
  self.set_result(await self.__task__)
82
342
  return self._result
343
+
83
344
  @property
84
345
  def __task__(self) -> "asyncio.Task[T]":
346
+ """
347
+ Returns the asyncio task associated with the awaitable, creating it if necessary.
348
+
349
+ Example:
350
+ >>> future = ASyncFuture(asyncio.sleep(1, result=42))
351
+ >>> task = future.__task__
352
+ >>> isinstance(task, asyncio.Task)
353
+ True
354
+ """
85
355
  if self.__task is None:
86
356
  self.__task = asyncio.create_task(self.__awaitable__)
87
357
  return self.__task
358
+
88
359
  def __iter__(self):
360
+ """
361
+ Returns an iterator for the materialized result.
362
+
363
+ Example:
364
+ >>> future = ASyncFuture(asyncio.sleep(1, result=[1, 2, 3]))
365
+ >>> for item in future:
366
+ ... print(item)
367
+ 1
368
+ 2
369
+ 3
370
+ """
89
371
  return _materialize(self).__iter__()
372
+
90
373
  def __next__(self):
374
+ """
375
+ Returns the next item from the materialized result.
376
+
377
+ Example:
378
+ >>> future = ASyncFuture(asyncio.sleep(1, result=iter([1, 2, 3])))
379
+ >>> next(future)
380
+ 1
381
+ """
91
382
  return _materialize(self).__next__()
383
+
92
384
  def __enter__(self):
385
+ """
386
+ Enters the context of the materialized result.
387
+
388
+ Example:
389
+ >>> class SomeContext:
390
+ ... def __enter__(self):
391
+ ... return self
392
+ ... def __exit__(self, exc_type, exc_val, exc_tb):
393
+ ... pass
394
+ >>> future = ASyncFuture(asyncio.sleep(1, result=SomeContext()))
395
+ >>> with future as context:
396
+ ... context.do_something()
397
+ """
93
398
  return _materialize(self).__enter__()
399
+
94
400
  def __exit__(self, *args):
401
+ """
402
+ Exits the context of the materialized result.
403
+
404
+ Example:
405
+ >>> class SomeContext:
406
+ ... def __enter__(self):
407
+ ... return self
408
+ ... def __exit__(self, exc_type, exc_val, exc_tb):
409
+ ... pass
410
+ >>> future = ASyncFuture(asyncio.sleep(1, result=SomeContext()))
411
+ >>> with future as context:
412
+ ... pass
413
+ >>> # Context is exited here
414
+ """
95
415
  return _materialize(self).__exit__(*args)
416
+
96
417
  @overload
97
- def __add__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
418
+ def __add__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
419
+
98
420
  @overload
99
- def __add__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
421
+ def __add__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
422
+
100
423
  @overload
101
- def __add__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
424
+ def __add__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
425
+
102
426
  @overload
103
- def __add__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
427
+ def __add__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
428
+
104
429
  @overload
105
- def __add__(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
430
+ def __add__(
431
+ self: "ASyncFuture[Decimal]", other: Decimal
432
+ ) -> "ASyncFuture[Decimal]": ...
433
+
106
434
  @overload
107
- def __add__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
435
+ def __add__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]": ...
436
+
108
437
  @overload
109
- def __add__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
438
+ def __add__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]": ...
439
+
110
440
  @overload
111
- def __add__(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
441
+ def __add__(
442
+ self: "ASyncFuture[int]", other: Awaitable[int]
443
+ ) -> "ASyncFuture[int]": ...
444
+
112
445
  @overload
113
- def __add__(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
446
+ def __add__(
447
+ self: "ASyncFuture[float]", other: Awaitable[float]
448
+ ) -> "ASyncFuture[float]": ...
449
+
114
450
  @overload
115
- def __add__(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
451
+ def __add__(
452
+ self: "ASyncFuture[float]", other: Awaitable[int]
453
+ ) -> "ASyncFuture[float]": ...
454
+
116
455
  @overload
117
- def __add__(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
456
+ def __add__(
457
+ self: "ASyncFuture[int]", other: Awaitable[float]
458
+ ) -> "ASyncFuture[float]": ...
459
+
118
460
  @overload
119
- def __add__(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
461
+ def __add__(
462
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
463
+ ) -> "ASyncFuture[Decimal]": ...
464
+
120
465
  @overload
121
- def __add__(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
466
+ def __add__(
467
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
468
+ ) -> "ASyncFuture[Decimal]": ...
469
+
122
470
  @overload
123
- def __add__(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
471
+ def __add__(
472
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
473
+ ) -> "ASyncFuture[Decimal]": ...
474
+
124
475
  def __add__(self, other: MetaNumeric) -> "ASyncFuture":
125
- return ASyncFuture(self.__add(other), dependencies=self.__list_dependencies(other))
476
+ """
477
+ Adds the result of this `ASyncFuture` to another value or `ASyncFuture`.
478
+
479
+ Args:
480
+ other: The value or `ASyncFuture` to add.
481
+
482
+ Returns:
483
+ A new `ASyncFuture` representing the sum.
484
+
485
+ Example:
486
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
487
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=5))
488
+ >>> result = future1 + future2
489
+ >>> await result
490
+ 15
491
+ """
492
+ return ASyncFuture(
493
+ self.__add(other), dependencies=self.__list_dependencies(other)
494
+ )
495
+
126
496
  @overload
127
- def __sub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
497
+ def __sub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
498
+
128
499
  @overload
129
- def __sub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
500
+ def __sub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
501
+
130
502
  @overload
131
- def __sub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
503
+ def __sub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
504
+
132
505
  @overload
133
- def __sub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
506
+ def __sub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
507
+
134
508
  @overload
135
- def __sub__(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
509
+ def __sub__(
510
+ self: "ASyncFuture[Decimal]", other: Decimal
511
+ ) -> "ASyncFuture[Decimal]": ...
512
+
136
513
  @overload
137
- def __sub__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
514
+ def __sub__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]": ...
515
+
138
516
  @overload
139
- def __sub__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
517
+ def __sub__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]": ...
518
+
140
519
  @overload
141
- def __sub__(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
520
+ def __sub__(
521
+ self: "ASyncFuture[int]", other: Awaitable[int]
522
+ ) -> "ASyncFuture[int]": ...
523
+
142
524
  @overload
143
- def __sub__(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
525
+ def __sub__(
526
+ self: "ASyncFuture[float]", other: Awaitable[float]
527
+ ) -> "ASyncFuture[float]": ...
528
+
144
529
  @overload
145
- def __sub__(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
530
+ def __sub__(
531
+ self: "ASyncFuture[float]", other: Awaitable[int]
532
+ ) -> "ASyncFuture[float]": ...
533
+
146
534
  @overload
147
- def __sub__(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
535
+ def __sub__(
536
+ self: "ASyncFuture[int]", other: Awaitable[float]
537
+ ) -> "ASyncFuture[float]": ...
538
+
148
539
  @overload
149
- def __sub__(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
540
+ def __sub__(
541
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
542
+ ) -> "ASyncFuture[Decimal]": ...
543
+
150
544
  @overload
151
- def __sub__(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
545
+ def __sub__(
546
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
547
+ ) -> "ASyncFuture[Decimal]": ...
548
+
152
549
  @overload
153
- def __sub__(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
550
+ def __sub__(
551
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
552
+ ) -> "ASyncFuture[Decimal]": ...
553
+
154
554
  def __sub__(self, other: MetaNumeric) -> "ASyncFuture":
155
- return ASyncFuture(self.__sub(other), dependencies=self.__list_dependencies(other))
555
+ """
556
+ Subtracts another value or `ASyncFuture` from the result of this `ASyncFuture`.
557
+
558
+ Args:
559
+ other: The value or `ASyncFuture` to subtract.
560
+
561
+ Returns:
562
+ A new `ASyncFuture` representing the difference.
563
+
564
+ Example:
565
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
566
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=5))
567
+ >>> result = future1 - future2
568
+ >>> await result
569
+ 5
570
+ """
571
+ return ASyncFuture(
572
+ self.__sub(other), dependencies=self.__list_dependencies(other)
573
+ )
574
+
156
575
  def __mul__(self, other) -> "ASyncFuture":
157
- return ASyncFuture(self.__mul(other), dependencies=self.__list_dependencies(other))
576
+ """
577
+ Multiplies the result of this `ASyncFuture` by another value or `ASyncFuture`.
578
+
579
+ Args:
580
+ other: The value or `ASyncFuture` to multiply.
581
+
582
+ Returns:
583
+ A new `ASyncFuture` representing the product.
584
+
585
+ Example:
586
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
587
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=5))
588
+ >>> result = future1 * future2
589
+ >>> await result
590
+ 50
591
+ """
592
+ return ASyncFuture(
593
+ self.__mul(other), dependencies=self.__list_dependencies(other)
594
+ )
595
+
158
596
  def __pow__(self, other) -> "ASyncFuture":
159
- return ASyncFuture(self.__pow(other), dependencies=self.__list_dependencies(other))
597
+ """
598
+ Raises the result of this `ASyncFuture` to the power of another value or `ASyncFuture`.
599
+
600
+ Args:
601
+ other: The exponent value or `ASyncFuture`.
602
+
603
+ Returns:
604
+ A new `ASyncFuture` representing the power.
605
+
606
+ Example:
607
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=2))
608
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=3))
609
+ >>> result = future1 ** future2
610
+ >>> await result
611
+ 8
612
+ """
613
+ return ASyncFuture(
614
+ self.__pow(other), dependencies=self.__list_dependencies(other)
615
+ )
616
+
160
617
  def __truediv__(self, other) -> "ASyncFuture":
161
- return ASyncFuture(self.__truediv(other), dependencies=self.__list_dependencies(other))
618
+ """
619
+ Divides the result of this `ASyncFuture` by another value or `ASyncFuture`.
620
+
621
+ Args:
622
+ other: The divisor value or `ASyncFuture`.
623
+
624
+ Returns:
625
+ A new `ASyncFuture` representing the quotient.
626
+
627
+ Example:
628
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
629
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=2))
630
+ >>> result = future1 / future2
631
+ >>> await result
632
+ 5.0
633
+ """
634
+ return ASyncFuture(
635
+ self.__truediv(other), dependencies=self.__list_dependencies(other)
636
+ )
637
+
162
638
  def __floordiv__(self, other) -> "ASyncFuture":
163
- return ASyncFuture(self.__floordiv(other), dependencies=self.__list_dependencies(other))
639
+ """
640
+ Performs floor division of the result of this `ASyncFuture` by another value or `ASyncFuture`.
641
+
642
+ Args:
643
+ other: The divisor value or `ASyncFuture`.
644
+
645
+ Returns:
646
+ A new `ASyncFuture` representing the floor division result.
647
+
648
+ Example:
649
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
650
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=3))
651
+ >>> result = future1 // future2
652
+ >>> await result
653
+ 3
654
+ """
655
+ return ASyncFuture(
656
+ self.__floordiv(other), dependencies=self.__list_dependencies(other)
657
+ )
658
+
164
659
  def __pow__(self, other) -> "ASyncFuture":
165
- return ASyncFuture(self.__pow(other), dependencies=self.__list_dependencies(other))
660
+ """
661
+ Raises the result of this `ASyncFuture` to the power of another value or `ASyncFuture`.
662
+
663
+ Args:
664
+ other: The exponent value or `ASyncFuture`.
665
+
666
+ Returns:
667
+ A new `ASyncFuture` representing the power.
668
+
669
+ Example:
670
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=2))
671
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=3))
672
+ >>> result = future1 ** future2
673
+ >>> await result
674
+ 8
675
+ """
676
+ return ASyncFuture(
677
+ self.__pow(other), dependencies=self.__list_dependencies(other)
678
+ )
679
+
166
680
  @overload
167
- def __radd__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
681
+ def __radd__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
682
+
168
683
  @overload
169
- def __radd__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
684
+ def __radd__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
685
+
170
686
  @overload
171
- def __radd__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
687
+ def __radd__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
688
+
172
689
  @overload
173
- def __radd__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
690
+ def __radd__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
691
+
174
692
  @overload
175
- def __radd__(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
693
+ def __radd__(
694
+ self: "ASyncFuture[Decimal]", other: Decimal
695
+ ) -> "ASyncFuture[Decimal]": ...
696
+
176
697
  @overload
177
- def __radd__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
698
+ def __radd__(
699
+ self: "ASyncFuture[Decimal]", other: int
700
+ ) -> "ASyncFuture[Decimal]": ...
701
+
178
702
  @overload
179
- def __radd__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
703
+ def __radd__(
704
+ self: "ASyncFuture[int]", other: Decimal
705
+ ) -> "ASyncFuture[Decimal]": ...
706
+
180
707
  @overload
181
- def __radd__(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
708
+ def __radd__(
709
+ self: "ASyncFuture[int]", other: Awaitable[int]
710
+ ) -> "ASyncFuture[int]": ...
711
+
182
712
  @overload
183
- def __radd__(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
713
+ def __radd__(
714
+ self: "ASyncFuture[float]", other: Awaitable[float]
715
+ ) -> "ASyncFuture[float]": ...
716
+
184
717
  @overload
185
- def __radd__(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
718
+ def __radd__(
719
+ self: "ASyncFuture[float]", other: Awaitable[int]
720
+ ) -> "ASyncFuture[float]": ...
721
+
186
722
  @overload
187
- def __radd__(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
723
+ def __radd__(
724
+ self: "ASyncFuture[int]", other: Awaitable[float]
725
+ ) -> "ASyncFuture[float]": ...
726
+
188
727
  @overload
189
- def __radd__(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
728
+ def __radd__(
729
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
730
+ ) -> "ASyncFuture[Decimal]": ...
731
+
190
732
  @overload
191
- def __radd__(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
733
+ def __radd__(
734
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
735
+ ) -> "ASyncFuture[Decimal]": ...
736
+
192
737
  @overload
193
- def __radd__(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
738
+ def __radd__(
739
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
740
+ ) -> "ASyncFuture[Decimal]": ...
741
+
194
742
  def __radd__(self, other) -> "ASyncFuture":
195
- return ASyncFuture(self.__radd(other), dependencies=self.__list_dependencies(other))
196
-
743
+ """
744
+ Adds another value or `ASyncFuture` to the result of this `ASyncFuture`.
745
+
746
+ Args:
747
+ other: The value or `ASyncFuture` to add.
748
+
749
+ Returns:
750
+ A new `ASyncFuture` representing the sum.
751
+
752
+ Example:
753
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
754
+ >>> result = 5 + future1
755
+ >>> await result
756
+ 15
757
+ """
758
+ return ASyncFuture(
759
+ self.__radd(other), dependencies=self.__list_dependencies(other)
760
+ )
761
+
197
762
  @overload
198
- def __rsub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
763
+ def __rsub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
764
+
199
765
  @overload
200
- def __rsub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
766
+ def __rsub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
767
+
201
768
  @overload
202
- def __rsub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
769
+ def __rsub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
770
+
203
771
  @overload
204
- def __rsub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
772
+ def __rsub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
773
+
205
774
  @overload
206
- def __rsub__(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
775
+ def __rsub__(
776
+ self: "ASyncFuture[Decimal]", other: Decimal
777
+ ) -> "ASyncFuture[Decimal]": ...
778
+
207
779
  @overload
208
- def __rsub__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
780
+ def __rsub__(
781
+ self: "ASyncFuture[Decimal]", other: int
782
+ ) -> "ASyncFuture[Decimal]": ...
783
+
209
784
  @overload
210
- def __rsub__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
785
+ def __rsub__(
786
+ self: "ASyncFuture[int]", other: Decimal
787
+ ) -> "ASyncFuture[Decimal]": ...
788
+
211
789
  @overload
212
- def __rsub__(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
790
+ def __rsub__(
791
+ self: "ASyncFuture[int]", other: Awaitable[int]
792
+ ) -> "ASyncFuture[int]": ...
793
+
213
794
  @overload
214
- def __rsub__(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
795
+ def __rsub__(
796
+ self: "ASyncFuture[float]", other: Awaitable[float]
797
+ ) -> "ASyncFuture[float]": ...
798
+
215
799
  @overload
216
- def __rsub__(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
800
+ def __rsub__(
801
+ self: "ASyncFuture[float]", other: Awaitable[int]
802
+ ) -> "ASyncFuture[float]": ...
803
+
217
804
  @overload
218
- def __rsub__(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
805
+ def __rsub__(
806
+ self: "ASyncFuture[int]", other: Awaitable[float]
807
+ ) -> "ASyncFuture[float]": ...
808
+
219
809
  @overload
220
- def __rsub__(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
810
+ def __rsub__(
811
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
812
+ ) -> "ASyncFuture[Decimal]": ...
813
+
221
814
  @overload
222
- def __rsub__(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
815
+ def __rsub__(
816
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
817
+ ) -> "ASyncFuture[Decimal]": ...
818
+
223
819
  @overload
224
- def __rsub__(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
820
+ def __rsub__(
821
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
822
+ ) -> "ASyncFuture[Decimal]": ...
823
+
225
824
  def __rsub__(self, other) -> "ASyncFuture":
226
- return ASyncFuture(self.__rsub(other), dependencies=self.__list_dependencies(other))
825
+ """
826
+ Subtracts the result of this `ASyncFuture` from another value or `ASyncFuture`.
827
+
828
+ Args:
829
+ other: The value or `ASyncFuture` to subtract from.
830
+
831
+ Returns:
832
+ A new `ASyncFuture` representing the difference.
833
+
834
+ Example:
835
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
836
+ >>> result = 20 - future1
837
+ >>> await result
838
+ 10
839
+ """
840
+ return ASyncFuture(
841
+ self.__rsub(other), dependencies=self.__list_dependencies(other)
842
+ )
843
+
227
844
  def __rmul__(self, other) -> "ASyncFuture":
228
- return ASyncFuture(self.__rmul(other), dependencies=self.__list_dependencies(other))
845
+ """
846
+ Multiplies another value or `ASyncFuture` by the result of this `ASyncFuture`.
847
+
848
+ Args:
849
+ other: The value or `ASyncFuture` to multiply.
850
+
851
+ Returns:
852
+ A new `ASyncFuture` representing the product.
853
+
854
+ Example:
855
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
856
+ >>> result = 2 * future1
857
+ >>> await result
858
+ 20
859
+ """
860
+ return ASyncFuture(
861
+ self.__rmul(other), dependencies=self.__list_dependencies(other)
862
+ )
863
+
229
864
  def __rtruediv__(self, other) -> "ASyncFuture":
230
- return ASyncFuture(self.__rtruediv(other), dependencies=self.__list_dependencies(other))
865
+ """
866
+ Divides another value or `ASyncFuture` by the result of this `ASyncFuture`.
867
+
868
+ Args:
869
+ other: The value or `ASyncFuture` to divide.
870
+
871
+ Returns:
872
+ A new `ASyncFuture` representing the quotient.
873
+
874
+ Example:
875
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=2))
876
+ >>> result = 10 / future1
877
+ >>> await result
878
+ 5.0
879
+ """
880
+ return ASyncFuture(
881
+ self.__rtruediv(other), dependencies=self.__list_dependencies(other)
882
+ )
883
+
231
884
  def __rfloordiv__(self, other) -> "ASyncFuture":
232
- return ASyncFuture(self.__rfloordiv(other), dependencies=self.__list_dependencies(other))
885
+ """
886
+ Performs floor division of another value or `ASyncFuture` by the result of this `ASyncFuture`.
887
+
888
+ Args:
889
+ other: The value or `ASyncFuture` to divide.
890
+
891
+ Returns:
892
+ A new `ASyncFuture` representing the floor division result.
893
+
894
+ Example:
895
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=3))
896
+ >>> result = 10 // future1
897
+ >>> await result
898
+ 3
899
+ """
900
+ return ASyncFuture(
901
+ self.__rfloordiv(other), dependencies=self.__list_dependencies(other)
902
+ )
903
+
233
904
  def __rpow__(self, other) -> "ASyncFuture":
234
- return ASyncFuture(self.__rpow(other), dependencies=self.__list_dependencies(other))
905
+ """
906
+ Raises another value or `ASyncFuture` to the power of the result of this `ASyncFuture`.
907
+
908
+ Args:
909
+ other: The base value or `ASyncFuture`.
910
+
911
+ Returns:
912
+ A new `ASyncFuture` representing the power.
913
+
914
+ Example:
915
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=3))
916
+ >>> result = 2 ** future1
917
+ >>> await result
918
+ 8
919
+ """
920
+ return ASyncFuture(
921
+ self.__rpow(other), dependencies=self.__list_dependencies(other)
922
+ )
923
+
235
924
  def __eq__(self, other) -> "ASyncFuture":
236
- return bool(ASyncFuture(self.__eq(other), dependencies=self.__list_dependencies(other)))
925
+ """
926
+ Compares the result of this `ASyncFuture` with another value or `ASyncFuture` for equality.
927
+
928
+ Args:
929
+ other: The value or `ASyncFuture` to compare.
930
+
931
+ Returns:
932
+ A new `ASyncFuture` representing the equality comparison result.
933
+
934
+ Example:
935
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
936
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=10))
937
+ >>> result = future1 == future2
938
+ >>> await result
939
+ True
940
+ """
941
+ return bool(
942
+ ASyncFuture(self.__eq(other), dependencies=self.__list_dependencies(other))
943
+ )
944
+
237
945
  def __gt__(self, other) -> "ASyncFuture":
238
- return ASyncFuture(self.__gt(other), dependencies=self.__list_dependencies(other))
946
+ """
947
+ Compares the result of this `ASyncFuture` with another value or `ASyncFuture` for greater than.
948
+
949
+ Args:
950
+ other: The value or `ASyncFuture` to compare.
951
+
952
+ Returns:
953
+ A new `ASyncFuture` representing the greater than comparison result.
954
+
955
+ Example:
956
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
957
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=5))
958
+ >>> result = future1 > future2
959
+ >>> await result
960
+ True
961
+ """
962
+ return ASyncFuture(
963
+ self.__gt(other), dependencies=self.__list_dependencies(other)
964
+ )
965
+
239
966
  def __ge__(self, other) -> "ASyncFuture":
240
- return ASyncFuture(self.__ge(other), dependencies=self.__list_dependencies(other))
967
+ """
968
+ Compares the result of this `ASyncFuture` with another value or `ASyncFuture` for greater than or equal.
969
+
970
+ Args:
971
+ other: The value or `ASyncFuture` to compare.
972
+
973
+ Returns:
974
+ A new `ASyncFuture` representing the greater than or equal comparison result.
975
+
976
+ Example:
977
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=10))
978
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=10))
979
+ >>> result = future1 >= future2
980
+ >>> await result
981
+ True
982
+ """
983
+ return ASyncFuture(
984
+ self.__ge(other), dependencies=self.__list_dependencies(other)
985
+ )
986
+
241
987
  def __lt__(self, other) -> "ASyncFuture":
242
- return ASyncFuture(self.__lt(other), dependencies=self.__list_dependencies(other))
988
+ """
989
+ Compares the result of this `ASyncFuture` with another value or `ASyncFuture` for less than.
990
+
991
+ Args:
992
+ other: The value or `ASyncFuture` to compare.
993
+
994
+ Returns:
995
+ A new `ASyncFuture` representing the less than comparison result.
996
+
997
+ Example:
998
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=5))
999
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=10))
1000
+ >>> result = future1 < future2
1001
+ >>> await result
1002
+ True
1003
+ """
1004
+ return ASyncFuture(
1005
+ self.__lt(other), dependencies=self.__list_dependencies(other)
1006
+ )
1007
+
243
1008
  def __le__(self, other) -> "ASyncFuture":
244
- return ASyncFuture(self.__le(other), dependencies=self.__list_dependencies(other))
245
-
1009
+ """
1010
+ Compares the result of this `ASyncFuture` with another value or `ASyncFuture` for less than or equal.
1011
+
1012
+ Args:
1013
+ other: The value or `ASyncFuture` to compare.
1014
+
1015
+ Returns:
1016
+ A new `ASyncFuture` representing the less than or equal comparison result.
1017
+
1018
+ Example:
1019
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=5))
1020
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=5))
1021
+ >>> result = future1 <= future2
1022
+ >>> await result
1023
+ True
1024
+ """
1025
+ return ASyncFuture(
1026
+ self.__le(other), dependencies=self.__list_dependencies(other)
1027
+ )
1028
+
246
1029
  # Maths
247
-
1030
+
248
1031
  @overload
249
- async def __add(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
1032
+ async def __add(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
1033
+
250
1034
  @overload
251
- async def __add(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
1035
+ async def __add(
1036
+ self: "ASyncFuture[float]", other: float
1037
+ ) -> "ASyncFuture[float]": ...
1038
+
252
1039
  @overload
253
- async def __add(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
1040
+ async def __add(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
1041
+
254
1042
  @overload
255
- async def __add(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
1043
+ async def __add(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
1044
+
256
1045
  @overload
257
- async def __add(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
1046
+ async def __add(
1047
+ self: "ASyncFuture[Decimal]", other: Decimal
1048
+ ) -> "ASyncFuture[Decimal]": ...
1049
+
258
1050
  @overload
259
- async def __add(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
1051
+ async def __add(
1052
+ self: "ASyncFuture[Decimal]", other: int
1053
+ ) -> "ASyncFuture[Decimal]": ...
1054
+
260
1055
  @overload
261
- async def __add(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
1056
+ async def __add(
1057
+ self: "ASyncFuture[int]", other: Decimal
1058
+ ) -> "ASyncFuture[Decimal]": ...
1059
+
262
1060
  @overload
263
- async def __add(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
1061
+ async def __add(
1062
+ self: "ASyncFuture[int]", other: Awaitable[int]
1063
+ ) -> "ASyncFuture[int]": ...
1064
+
264
1065
  @overload
265
- async def __add(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
1066
+ async def __add(
1067
+ self: "ASyncFuture[float]", other: Awaitable[float]
1068
+ ) -> "ASyncFuture[float]": ...
1069
+
266
1070
  @overload
267
- async def __add(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
1071
+ async def __add(
1072
+ self: "ASyncFuture[float]", other: Awaitable[int]
1073
+ ) -> "ASyncFuture[float]": ...
1074
+
268
1075
  @overload
269
- async def __add(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
1076
+ async def __add(
1077
+ self: "ASyncFuture[int]", other: Awaitable[float]
1078
+ ) -> "ASyncFuture[float]": ...
1079
+
270
1080
  @overload
271
- async def __add(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
1081
+ async def __add(
1082
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
1083
+ ) -> "ASyncFuture[Decimal]": ...
1084
+
272
1085
  @overload
273
- async def __add(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
1086
+ async def __add(
1087
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
1088
+ ) -> "ASyncFuture[Decimal]": ...
1089
+
274
1090
  @overload
275
- async def __add(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
1091
+ async def __add(
1092
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
1093
+ ) -> "ASyncFuture[Decimal]": ...
1094
+
276
1095
  async def __add(self, other) -> "Any":
277
1096
  a, b = await _gather_check_and_materialize(self, other)
278
1097
  return a + b
1098
+
279
1099
  @overload
280
- async def __sub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
1100
+ async def __sub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
1101
+
281
1102
  @overload
282
- async def __sub(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
1103
+ async def __sub(
1104
+ self: "ASyncFuture[float]", other: float
1105
+ ) -> "ASyncFuture[float]": ...
1106
+
283
1107
  @overload
284
- async def __sub(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
1108
+ async def __sub(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
1109
+
285
1110
  @overload
286
- async def __sub(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
1111
+ async def __sub(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
1112
+
287
1113
  @overload
288
- async def __sub(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
1114
+ async def __sub(
1115
+ self: "ASyncFuture[Decimal]", other: Decimal
1116
+ ) -> "ASyncFuture[Decimal]": ...
1117
+
289
1118
  @overload
290
- async def __sub(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
1119
+ async def __sub(
1120
+ self: "ASyncFuture[Decimal]", other: int
1121
+ ) -> "ASyncFuture[Decimal]": ...
1122
+
291
1123
  @overload
292
- async def __sub(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
1124
+ async def __sub(
1125
+ self: "ASyncFuture[int]", other: Decimal
1126
+ ) -> "ASyncFuture[Decimal]": ...
1127
+
293
1128
  @overload
294
- async def __sub(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
1129
+ async def __sub(
1130
+ self: "ASyncFuture[int]", other: Awaitable[int]
1131
+ ) -> "ASyncFuture[int]": ...
1132
+
295
1133
  @overload
296
- async def __sub(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
1134
+ async def __sub(
1135
+ self: "ASyncFuture[float]", other: Awaitable[float]
1136
+ ) -> "ASyncFuture[float]": ...
1137
+
297
1138
  @overload
298
- async def __sub(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
1139
+ async def __sub(
1140
+ self: "ASyncFuture[float]", other: Awaitable[int]
1141
+ ) -> "ASyncFuture[float]": ...
1142
+
299
1143
  @overload
300
- async def __sub(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
1144
+ async def __sub(
1145
+ self: "ASyncFuture[int]", other: Awaitable[float]
1146
+ ) -> "ASyncFuture[float]": ...
1147
+
301
1148
  @overload
302
- async def __sub(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
1149
+ async def __sub(
1150
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
1151
+ ) -> "ASyncFuture[Decimal]": ...
1152
+
303
1153
  @overload
304
- async def __sub(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
1154
+ async def __sub(
1155
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
1156
+ ) -> "ASyncFuture[Decimal]": ...
1157
+
305
1158
  @overload
306
- async def __sub(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
1159
+ async def __sub(
1160
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
1161
+ ) -> "ASyncFuture[Decimal]": ...
1162
+
307
1163
  async def __sub(self, other) -> "Any":
308
1164
  a, b = await _gather_check_and_materialize(self, other)
309
1165
  return a - b
1166
+
310
1167
  async def __mul(self, other) -> "Any":
311
1168
  a, b = await _gather_check_and_materialize(self, other)
312
1169
  return a * b
1170
+
313
1171
  async def __truediv(self, other) -> "Any":
314
1172
  a, b = await _gather_check_and_materialize(self, other)
315
1173
  return a / b
1174
+
316
1175
  async def __floordiv(self, other) -> "Any":
317
1176
  a, b = await _gather_check_and_materialize(self, other)
318
1177
  return a // b
1178
+
319
1179
  async def __pow(self, other) -> "Any":
320
1180
  a, b = await _gather_check_and_materialize(self, other)
321
- return a ** b
322
-
1181
+ return a**b
1182
+
323
1183
  # rMaths
324
1184
  @overload
325
- async def __radd(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
1185
+ async def __radd(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
1186
+
326
1187
  @overload
327
- async def __radd(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
1188
+ async def __radd(
1189
+ self: "ASyncFuture[float]", other: float
1190
+ ) -> "ASyncFuture[float]": ...
1191
+
328
1192
  @overload
329
- async def __radd(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
1193
+ async def __radd(
1194
+ self: "ASyncFuture[float]", other: int
1195
+ ) -> "ASyncFuture[float]": ...
1196
+
330
1197
  @overload
331
- async def __radd(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
1198
+ async def __radd(
1199
+ self: "ASyncFuture[int]", other: float
1200
+ ) -> "ASyncFuture[float]": ...
1201
+
332
1202
  @overload
333
- async def __radd(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
1203
+ async def __radd(
1204
+ self: "ASyncFuture[Decimal]", other: Decimal
1205
+ ) -> "ASyncFuture[Decimal]": ...
1206
+
334
1207
  @overload
335
- async def __radd(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
1208
+ async def __radd(
1209
+ self: "ASyncFuture[Decimal]", other: int
1210
+ ) -> "ASyncFuture[Decimal]": ...
1211
+
336
1212
  @overload
337
- async def __radd(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
1213
+ async def __radd(
1214
+ self: "ASyncFuture[int]", other: Decimal
1215
+ ) -> "ASyncFuture[Decimal]": ...
1216
+
338
1217
  @overload
339
- async def __radd(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
1218
+ async def __radd(
1219
+ self: "ASyncFuture[int]", other: Awaitable[int]
1220
+ ) -> "ASyncFuture[int]": ...
1221
+
340
1222
  @overload
341
- async def __radd(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
1223
+ async def __radd(
1224
+ self: "ASyncFuture[float]", other: Awaitable[float]
1225
+ ) -> "ASyncFuture[float]": ...
1226
+
342
1227
  @overload
343
- async def __radd(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
1228
+ async def __radd(
1229
+ self: "ASyncFuture[float]", other: Awaitable[int]
1230
+ ) -> "ASyncFuture[float]": ...
1231
+
344
1232
  @overload
345
- async def __radd(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
1233
+ async def __radd(
1234
+ self: "ASyncFuture[int]", other: Awaitable[float]
1235
+ ) -> "ASyncFuture[float]": ...
1236
+
346
1237
  @overload
347
- async def __radd(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
1238
+ async def __radd(
1239
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
1240
+ ) -> "ASyncFuture[Decimal]": ...
1241
+
348
1242
  @overload
349
- async def __radd(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
1243
+ async def __radd(
1244
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
1245
+ ) -> "ASyncFuture[Decimal]": ...
1246
+
350
1247
  @overload
351
- async def __radd(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
1248
+ async def __radd(
1249
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
1250
+ ) -> "ASyncFuture[Decimal]": ...
1251
+
352
1252
  async def __radd(self, other) -> "Any":
353
1253
  a, b = await _gather_check_and_materialize(other, self)
354
1254
  return a + b
1255
+
355
1256
  @overload
356
- async def __rsub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]":...
1257
+ async def __rsub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
1258
+
357
1259
  @overload
358
- async def __rsub(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]":...
1260
+ async def __rsub(
1261
+ self: "ASyncFuture[float]", other: float
1262
+ ) -> "ASyncFuture[float]": ...
1263
+
359
1264
  @overload
360
- async def __rsub(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]":...
1265
+ async def __rsub(
1266
+ self: "ASyncFuture[float]", other: int
1267
+ ) -> "ASyncFuture[float]": ...
1268
+
361
1269
  @overload
362
- async def __rsub(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]":...
1270
+ async def __rsub(
1271
+ self: "ASyncFuture[int]", other: float
1272
+ ) -> "ASyncFuture[float]": ...
1273
+
363
1274
  @overload
364
- async def __rsub(self: "ASyncFuture[Decimal]", other: Decimal) -> "ASyncFuture[Decimal]":...
1275
+ async def __rsub(
1276
+ self: "ASyncFuture[Decimal]", other: Decimal
1277
+ ) -> "ASyncFuture[Decimal]": ...
1278
+
365
1279
  @overload
366
- async def __rsub(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]":...
1280
+ async def __rsub(
1281
+ self: "ASyncFuture[Decimal]", other: int
1282
+ ) -> "ASyncFuture[Decimal]": ...
1283
+
367
1284
  @overload
368
- async def __rsub(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]":...
1285
+ async def __rsub(
1286
+ self: "ASyncFuture[int]", other: Decimal
1287
+ ) -> "ASyncFuture[Decimal]": ...
1288
+
369
1289
  @overload
370
- async def __rsub(self: "ASyncFuture[int]", other: Awaitable[int]) -> "ASyncFuture[int]":...
1290
+ async def __rsub(
1291
+ self: "ASyncFuture[int]", other: Awaitable[int]
1292
+ ) -> "ASyncFuture[int]": ...
1293
+
371
1294
  @overload
372
- async def __rsub(self: "ASyncFuture[float]", other: Awaitable[float]) -> "ASyncFuture[float]":...
1295
+ async def __rsub(
1296
+ self: "ASyncFuture[float]", other: Awaitable[float]
1297
+ ) -> "ASyncFuture[float]": ...
1298
+
373
1299
  @overload
374
- async def __rsub(self: "ASyncFuture[float]", other: Awaitable[int]) -> "ASyncFuture[float]":...
1300
+ async def __rsub(
1301
+ self: "ASyncFuture[float]", other: Awaitable[int]
1302
+ ) -> "ASyncFuture[float]": ...
1303
+
375
1304
  @overload
376
- async def __rsub(self: "ASyncFuture[int]", other: Awaitable[float]) -> "ASyncFuture[float]":...
1305
+ async def __rsub(
1306
+ self: "ASyncFuture[int]", other: Awaitable[float]
1307
+ ) -> "ASyncFuture[float]": ...
1308
+
377
1309
  @overload
378
- async def __rsub(self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
1310
+ async def __rsub(
1311
+ self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
1312
+ ) -> "ASyncFuture[Decimal]": ...
1313
+
379
1314
  @overload
380
- async def __rsub(self: "ASyncFuture[Decimal]", other: Awaitable[int]) -> "ASyncFuture[Decimal]":...
1315
+ async def __rsub(
1316
+ self: "ASyncFuture[Decimal]", other: Awaitable[int]
1317
+ ) -> "ASyncFuture[Decimal]": ...
1318
+
381
1319
  @overload
382
- async def __rsub(self: "ASyncFuture[int]", other: Awaitable[Decimal]) -> "ASyncFuture[Decimal]":...
1320
+ async def __rsub(
1321
+ self: "ASyncFuture[int]", other: Awaitable[Decimal]
1322
+ ) -> "ASyncFuture[Decimal]": ...
1323
+
383
1324
  async def __rsub(self, other) -> "Any":
384
1325
  a, b = await _gather_check_and_materialize(other, self)
385
1326
  return a - b
1327
+
386
1328
  async def __rmul(self, other) -> "Any":
387
1329
  a, b = await _gather_check_and_materialize(other, self)
388
1330
  return a * b
1331
+
389
1332
  async def __rtruediv(self, other) -> "Any":
390
1333
  a, b = await _gather_check_and_materialize(other, self)
391
1334
  return a / b
1335
+
392
1336
  async def __rfloordiv(self, other) -> "Any":
393
1337
  a, b = await _gather_check_and_materialize(other, self)
394
1338
  return a // b
1339
+
395
1340
  async def __rpow(self, other) -> "Any":
396
1341
  a, b = await _gather_check_and_materialize(other, self)
397
- return a ** b
398
-
1342
+ return a**b
1343
+
399
1344
  async def __iadd(self, other) -> "Any":
400
1345
  a, b = await _gather_check_and_materialize(self, other)
401
1346
  self._result = a + b
402
1347
  return self._result
1348
+
403
1349
  async def __isub(self, other) -> "Any":
404
1350
  a, b = await _gather_check_and_materialize(self, other)
405
1351
  self._result = a - b
406
1352
  return self._result
1353
+
407
1354
  async def __imul(self, other) -> "Any":
408
1355
  a, b = await _gather_check_and_materialize(self, other)
409
1356
  self._result = a * b
410
1357
  return self._result
1358
+
411
1359
  async def __itruediv(self, other) -> "Any":
412
1360
  a, b = await _gather_check_and_materialize(self, other)
413
1361
  self._result = a / b
414
1362
  return self._result
1363
+
415
1364
  async def __ifloordiv(self, other) -> "Any":
416
1365
  a, b = await _gather_check_and_materialize(self, other)
417
1366
  self._result = a // b
418
1367
  return self._result
1368
+
419
1369
  async def __ipow(self, other) -> "Any":
420
1370
  a, b = await _gather_check_and_materialize(self, other)
421
- self._result = a ** b
1371
+ self._result = a**b
422
1372
  return self._result
423
-
1373
+
424
1374
  # Comparisons
425
1375
  async def __eq(self, other) -> bool:
426
1376
  a, b = await _gather_check_and_materialize(self, other)
427
1377
  return a == b
1378
+
428
1379
  async def __gt(self, other) -> bool:
429
1380
  a, b = await _gather_check_and_materialize(self, other)
430
1381
  return a > b
1382
+
431
1383
  async def __ge(self, other) -> bool:
432
1384
  a, b = await _gather_check_and_materialize(self, other)
433
1385
  return a >= b
1386
+
434
1387
  async def __lt(self, other) -> bool:
435
1388
  a, b = await _gather_check_and_materialize(self, other)
436
1389
  return a < b
1390
+
437
1391
  async def __le(self, other) -> bool:
438
1392
  a, b = await _gather_check_and_materialize(self, other)
439
1393
  return a <= b
440
1394
 
441
-
442
1395
  # not sure what to call these
443
1396
  async def __contains(self, item: Any) -> bool:
444
1397
  _self, _item = await _gather_check_and_materialize(self, item)
445
1398
  return _item in _self
446
-
1399
+
447
1400
  # conversion
448
1401
  # NOTE: We aren't allowed to return ASyncFutures here :(
449
1402
  def __bool__(self) -> bool:
450
1403
  return bool(_materialize(self))
1404
+
451
1405
  def __bytes__(self) -> bytes:
452
1406
  return bytes(_materialize(self))
1407
+
453
1408
  def __str__(self) -> str:
454
1409
  return str(_materialize(self))
1410
+
455
1411
  def __int__(self) -> int:
456
1412
  return int(_materialize(self))
1413
+
457
1414
  def __float__(self) -> float:
458
1415
  return float(_materialize(self))
459
-
1416
+
460
1417
  # WIP internals
461
-
1418
+
462
1419
  @property
463
1420
  def __dependants__(self) -> Set["ASyncFuture"]:
1421
+ """
1422
+ Returns the set of dependants for this `ASyncFuture`, including nested dependants.
1423
+
1424
+ Example:
1425
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=42))
1426
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=10), dependencies=[future1])
1427
+ >>> dependants = future1.__dependants__
1428
+ >>> future2 in dependants
1429
+ True
1430
+ """
464
1431
  dependants = set()
465
1432
  for dep in self.__dependants:
466
1433
  dependants.add(dep)
467
1434
  dependants.union(dep.__dependants__)
468
1435
  return dependants
1436
+
469
1437
  @property
470
1438
  def __dependencies__(self) -> Set["ASyncFuture"]:
1439
+ """
1440
+ Returns the set of dependencies for this `ASyncFuture`, including nested dependencies.
1441
+
1442
+ Example:
1443
+ >>> future1 = ASyncFuture(asyncio.sleep(1, result=42))
1444
+ >>> future2 = ASyncFuture(asyncio.sleep(1, result=10), dependencies=[future1])
1445
+ >>> dependencies = future2.__dependencies__
1446
+ >>> future1 in dependencies
1447
+ True
1448
+ """
471
1449
  dependencies = set()
472
1450
  for dep in self.__dependencies:
473
1451
  dependencies.add(dep)
474
1452
  dependencies.union(dep.__dependencies__)
475
1453
  return dependencies
1454
+
476
1455
  def __sizeof__(self) -> int:
477
1456
  if isinstance(self.__awaitable__, Coroutine):
478
- return sum(sys.getsizeof(v) for v in self.__awaitable__.cr_frame.f_locals.values())
1457
+ return sum(
1458
+ sys.getsizeof(v) for v in self.__awaitable__.cr_frame.f_locals.values()
1459
+ )
479
1460
  elif isinstance(self.__awaitable__, asyncio.Future):
480
1461
  raise NotImplementedError
481
1462
  raise NotImplementedError
482
1463
 
483
1464
 
484
- @final
1465
+ @final
485
1466
  class _ASyncFutureWrappedFn(Callable[P, ASyncFuture[T]]):
1467
+ """
1468
+ A callable class to wrap functions and return `ASyncFuture` objects.
1469
+
1470
+ This class is used internally by the `future` decorator to wrap a function
1471
+ and return an `ASyncFuture` when the function is called. It allows the
1472
+ function to be executed asynchronously and its result to be awaited.
1473
+
1474
+ Example:
1475
+ >>> def sync_fn():
1476
+ ... return 42
1477
+ >>> wrapped_fn = _ASyncFutureWrappedFn(sync_fn)
1478
+ >>> future = wrapped_fn()
1479
+ >>> isinstance(future, ASyncFuture)
1480
+ True
1481
+
1482
+ Note:
1483
+ This is not part of the public API. Use the `future` decorator instead.
1484
+ """
1485
+
486
1486
  __slots__ = "callable", "wrapped", "_callable_name"
487
- def __init__(self, callable: Union[Callable[P, Awaitable[T]], Callable[P, T]] = None, **kwargs: Unpack[ModifierKwargs]):
1487
+
1488
+ def __init__(
1489
+ self,
1490
+ callable: AnyFn[P, T] = None,
1491
+ **kwargs: Unpack[ModifierKwargs],
1492
+ ):
488
1493
  from a_sync import a_sync
1494
+
489
1495
  if callable:
490
1496
  self.callable = callable
1497
+ """The callable function."""
1498
+
491
1499
  self._callable_name = callable.__name__
1500
+ """The name of the callable function."""
1501
+
492
1502
  a_sync_callable = a_sync(callable, default="async", **kwargs)
1503
+
493
1504
  @wraps(callable)
494
1505
  def future_wrap(*args: P.args, **kwargs: P.kwargs) -> "ASyncFuture[T]":
495
1506
  return ASyncFuture(a_sync_callable(*args, **kwargs, sync=False))
1507
+
496
1508
  self.wrapped = future_wrap
1509
+ """The wrapped function returning ASyncFuture."""
497
1510
  else:
498
1511
  self.wrapped = partial(_ASyncFutureWrappedFn, **kwargs)
1512
+
499
1513
  def __call__(self, *args: P.args, **kwargs: P.kwargs) -> ASyncFuture[T]:
500
1514
  return self.wrapped(*args, **kwargs)
1515
+
501
1516
  def __repr__(self) -> str:
502
1517
  return f"<{self.__class__.__name__} {self.callable}>"
503
- def __get__(self, instance: I, owner: Type[I]) -> Union[Self, "_ASyncFutureInstanceMethod[I, P, T]"]:
504
- if owner is None:
505
- return self
506
- else:
507
- return _ASyncFutureInstanceMethod(self, instance)
1518
+
1519
+ def __get__(
1520
+ self, instance: I, owner: Type[I]
1521
+ ) -> Union[Self, "_ASyncFutureInstanceMethod[I, P, T]"]:
1522
+ return self if owner is None else _ASyncFutureInstanceMethod(self, instance)
1523
+
508
1524
 
509
1525
  @final
510
1526
  class _ASyncFutureInstanceMethod(Generic[I, P, T]):
511
1527
  # NOTE: probably could just replace this with functools.partial
1528
+ """
1529
+ A class to handle instance methods wrapped as `ASyncFuture`.
1530
+
1531
+ This class is used internally to manage instance methods that are wrapped
1532
+ by `_ASyncFutureWrappedFn`. It ensures that the method is bound to the
1533
+ instance and returns an `ASyncFuture` when called.
1534
+
1535
+ Example:
1536
+ >>> class MyClass:
1537
+ ... @_ASyncFutureWrappedFn
1538
+ ... def method(self):
1539
+ ... return 42
1540
+ >>> instance = MyClass()
1541
+ >>> future = instance.method()
1542
+ >>> isinstance(future, ASyncFuture)
1543
+ True
1544
+
1545
+ Note:
1546
+ This is not part of the public API. Use the `future` decorator instead.
1547
+ """
1548
+
1549
+ __module__: str
1550
+ """The module name of the wrapper."""
1551
+
1552
+ __name__: str
1553
+ """The name of the wrapper."""
1554
+
1555
+ __qualname__: str
1556
+ """The qualified name of the wrapper."""
1557
+
1558
+ __doc__: Optional[str]
1559
+ """The docstring of the wrapper."""
1560
+
1561
+ __annotations__: Dict[str, Any]
1562
+ """The annotations of the wrapper."""
1563
+
1564
+ __instance: I
1565
+ """The instance to which the method is bound."""
1566
+
1567
+ __wrapper: _ASyncFutureWrappedFn[P, T]
1568
+ """The wrapper function."""
1569
+
512
1570
  def __init__(
513
1571
  self,
514
1572
  wrapper: _ASyncFutureWrappedFn[P, T],
515
1573
  instance: I,
516
- ) -> None:
1574
+ ) -> None: # sourcery skip: use-contextlib-suppress
517
1575
  try:
518
1576
  self.__module__ = wrapper.__module__
519
1577
  except AttributeError:
@@ -543,6 +1601,7 @@ class _ASyncFutureInstanceMethod(Generic[I, P, T]):
543
1601
 
544
1602
  def __repr__(self) -> str:
545
1603
  return f"<{self.__class__.__name__} for {self.__wrapper.callable} bound to {self.__instance}>"
1604
+
546
1605
  def __call__(self, /, *fn_args: P.args, **fn_kwargs: P.kwargs) -> T:
547
1606
  return self.__wrapper(self.__instance, *fn_args, **fn_kwargs)
548
1607