ez-a-sync 0.22.15__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 (49) hide show
  1. a_sync/ENVIRONMENT_VARIABLES.py +34 -3
  2. a_sync/__init__.py +32 -9
  3. a_sync/_smart.py +105 -6
  4. a_sync/_typing.py +56 -3
  5. a_sync/a_sync/_descriptor.py +174 -12
  6. a_sync/a_sync/_flags.py +64 -3
  7. a_sync/a_sync/_helpers.py +40 -8
  8. a_sync/a_sync/_kwargs.py +30 -6
  9. a_sync/a_sync/_meta.py +35 -6
  10. a_sync/a_sync/abstract.py +57 -9
  11. a_sync/a_sync/config.py +44 -7
  12. a_sync/a_sync/decorator.py +217 -37
  13. a_sync/a_sync/function.py +339 -47
  14. a_sync/a_sync/method.py +241 -52
  15. a_sync/a_sync/modifiers/__init__.py +39 -1
  16. a_sync/a_sync/modifiers/cache/__init__.py +75 -5
  17. a_sync/a_sync/modifiers/cache/memory.py +50 -6
  18. a_sync/a_sync/modifiers/limiter.py +55 -6
  19. a_sync/a_sync/modifiers/manager.py +46 -2
  20. a_sync/a_sync/modifiers/semaphores.py +84 -11
  21. a_sync/a_sync/singleton.py +43 -19
  22. a_sync/asyncio/__init__.py +137 -1
  23. a_sync/asyncio/as_completed.py +44 -38
  24. a_sync/asyncio/create_task.py +46 -10
  25. a_sync/asyncio/gather.py +72 -25
  26. a_sync/exceptions.py +178 -11
  27. a_sync/executor.py +51 -3
  28. a_sync/future.py +671 -29
  29. a_sync/iter.py +64 -7
  30. a_sync/primitives/_debug.py +59 -5
  31. a_sync/primitives/_loggable.py +36 -6
  32. a_sync/primitives/locks/counter.py +74 -7
  33. a_sync/primitives/locks/prio_semaphore.py +87 -8
  34. a_sync/primitives/locks/semaphore.py +68 -20
  35. a_sync/primitives/queue.py +65 -26
  36. a_sync/task.py +51 -15
  37. a_sync/utils/iterators.py +52 -16
  38. {ez_a_sync-0.22.15.dist-info → ez_a_sync-0.22.16.dist-info}/METADATA +1 -1
  39. ez_a_sync-0.22.16.dist-info/RECORD +74 -0
  40. {ez_a_sync-0.22.15.dist-info → ez_a_sync-0.22.16.dist-info}/WHEEL +1 -1
  41. tests/executor.py +150 -12
  42. tests/test_abstract.py +15 -0
  43. tests/test_base.py +198 -2
  44. tests/test_executor.py +23 -0
  45. tests/test_singleton.py +13 -1
  46. tests/test_task.py +45 -17
  47. ez_a_sync-0.22.15.dist-info/RECORD +0 -74
  48. {ez_a_sync-0.22.15.dist-info → ez_a_sync-0.22.16.dist-info}/LICENSE.txt +0 -0
  49. {ez_a_sync-0.22.15.dist-info → ez_a_sync-0.22.16.dist-info}/top_level.txt +0 -0
a_sync/future.py CHANGED
@@ -1,24 +1,28 @@
1
1
  # type: ignore [var-annotated]
2
2
 
3
3
  """
4
- The future.py module provides functionality for handling asynchronous futures,
5
- including a decorator for converting callables into ASyncFuture objects and
4
+ The `future.py` module provides functionality for handling asynchronous futures,
5
+ including a decorator for converting callables into `ASyncFuture` objects and
6
6
  utilities for managing asynchronous computations.
7
7
 
8
8
  Functions:
9
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.
10
+ A decorator to convert a callable into an `ASyncFuture`, with optional modifiers.
11
11
  _gather_check_and_materialize(*things: Unpack[MaybeAwaitable[T]]) -> List[T]:
12
12
  Gathers and materializes a list of awaitable or non-awaitable items.
13
13
  _check_and_materialize(thing: T) -> T:
14
14
  Checks if an item is awaitable and materializes it.
15
15
  _materialize(meta: "ASyncFuture[T]") -> T:
16
- Materializes the result of an ASyncFuture.
16
+ Materializes the result of an `ASyncFuture`.
17
17
 
18
18
  Classes:
19
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.
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
22
26
  """
23
27
 
24
28
  import asyncio
@@ -34,11 +38,29 @@ def future(
34
38
  **kwargs: Unpack[ModifierKwargs],
35
39
  ) -> Callable[P, Union[T, "ASyncFuture[T]"]]:
36
40
  """
37
- A decorator function to convert a callable into an ASyncFuture, with optional modifiers.
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.
38
46
 
39
47
  Args:
40
48
  callable: The callable to convert. Defaults to None.
41
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`
42
64
  """
43
65
  return _ASyncFutureWrappedFn(callable, **kwargs)
44
66
 
@@ -47,8 +69,18 @@ async def _gather_check_and_materialize(*things: Unpack[MaybeAwaitable[T]]) -> L
47
69
  """
48
70
  Gathers and materializes a list of awaitable or non-awaitable items.
49
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
+
50
76
  Args:
51
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]
52
84
  """
53
85
  return await asyncio.gather(*[_check_and_materialize(thing) for thing in things])
54
86
 
@@ -57,21 +89,41 @@ async def _check_and_materialize(thing: T) -> T:
57
89
  """
58
90
  Checks if an item is awaitable and materializes it.
59
91
 
92
+ If the item is awaitable, it is awaited and the result is returned.
93
+ Otherwise, the item is returned as-is.
94
+
60
95
  Args:
61
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
62
103
  """
63
104
  return await thing if isawaitable(thing) else thing
64
105
 
65
106
 
66
107
  def _materialize(meta: "ASyncFuture[T]") -> T:
67
108
  """
68
- Materializes the result of an ASyncFuture.
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.
69
113
 
70
114
  Args:
71
- meta: The ASyncFuture to materialize.
115
+ meta: The `ASyncFuture` to materialize.
72
116
 
73
117
  Raises:
74
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`
75
127
  """
76
128
  try:
77
129
  return asyncio.get_event_loop().run_until_complete(meta)
@@ -86,36 +138,69 @@ MetaNumeric = Union[
86
138
  ]
87
139
 
88
140
 
141
+ @final
89
142
  class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
90
143
  """
91
144
  A class representing an asynchronous future result.
92
145
 
93
- Inherits from both concurrent.futures.Future and Awaitable[T], allowing it to be used in both synchronous and asynchronous contexts.
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
94
166
  """
95
167
 
96
168
  __slots__ = "__awaitable__", "__dependencies", "__dependants", "__task"
97
169
 
98
170
  def __init__(
99
171
  self, awaitable: Awaitable[T], dependencies: List["ASyncFuture"] = []
100
- ) -> None:
172
+ ) -> None: # sourcery skip: default-mutable-arg
101
173
  """
102
- Initializes an ASyncFuture with an awaitable and optional dependencies.
174
+ Initializes an `ASyncFuture` with an awaitable and optional dependencies.
103
175
 
104
176
  Args:
105
177
  awaitable: The awaitable object.
106
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
107
186
  """
187
+
108
188
  self.__awaitable__ = awaitable
109
189
  """The awaitable object."""
190
+
110
191
  self.__dependencies = dependencies
111
192
  """A list of dependencies."""
193
+
112
194
  for dependency in dependencies:
113
195
  assert isinstance(dependency, ASyncFuture)
114
196
  dependency.__dependants.append(self)
197
+
115
198
  self.__dependants: List[ASyncFuture] = []
116
199
  """A list of dependants."""
200
+
117
201
  self.__task = None
118
202
  """The task associated with the awaitable."""
203
+
119
204
  super().__init__()
120
205
 
121
206
  def __hash__(self) -> int:
@@ -131,25 +216,32 @@ class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
131
216
  if self.exception()
132
217
  else f" result={super().result()}"
133
218
  )
134
- return string + ">"
219
+ return f"{string}>"
135
220
 
136
221
  def __list_dependencies(self, other) -> List["ASyncFuture"]:
137
222
  """
138
- Lists dependencies for the ASyncFuture.
223
+ Lists dependencies for the `ASyncFuture`.
139
224
 
140
225
  Args:
141
226
  other: The other dependency to list.
227
+
228
+ Returns:
229
+ A list of dependencies including the current and other `ASyncFuture`.
142
230
  """
143
- if isinstance(other, ASyncFuture):
144
- return [self, other]
145
- return [self]
231
+ return [self, other] if isinstance(other, ASyncFuture) else [self]
146
232
 
147
233
  @property
148
234
  def result(self) -> Union[Callable[[], T], Any]:
235
+ # sourcery skip: assign-if-exp, reintroduce-else
149
236
  """
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.
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.
151
238
  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
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
153
245
  """
154
246
  if self.done():
155
247
  if hasattr(r := super().result(), "result"):
@@ -160,17 +252,73 @@ class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
160
252
  return lambda: _materialize(self)
161
253
 
162
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
+ """
163
272
  return getattr(_materialize(self), attr)
164
273
 
165
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
+ """
166
289
  return _materialize(self)[key]
167
290
 
168
291
  # NOTE: broken, do not use. I think
169
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
+ """
170
304
  _materialize(self)[key] = value
171
305
 
172
306
  # not sure what to call these
173
307
  def __contains__(self, key: Any) -> bool:
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
+ """
174
322
  return _materialize(
175
323
  ASyncFuture(
176
324
  self.__contains(key), dependencies=self.__list_dependencies(key)
@@ -179,7 +327,12 @@ class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
179
327
 
180
328
  def __await__(self) -> Generator[Any, None, T]:
181
329
  """
182
- Makes the ASyncFuture awaitable.
330
+ Makes the `ASyncFuture` awaitable.
331
+
332
+ Example:
333
+ >>> future = ASyncFuture(asyncio.sleep(1, result=42))
334
+ >>> await future
335
+ 42
183
336
  """
184
337
  return self.__await().__await__()
185
338
 
@@ -192,293 +345,683 @@ class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
192
345
  def __task__(self) -> "asyncio.Task[T]":
193
346
  """
194
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
195
354
  """
196
355
  if self.__task is None:
197
356
  self.__task = asyncio.create_task(self.__awaitable__)
198
357
  return self.__task
199
358
 
200
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
+ """
201
371
  return _materialize(self).__iter__()
202
372
 
203
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
+ """
204
382
  return _materialize(self).__next__()
205
383
 
206
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
+ """
207
398
  return _materialize(self).__enter__()
208
399
 
209
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
+ """
210
415
  return _materialize(self).__exit__(*args)
211
416
 
212
417
  @overload
213
418
  def __add__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
419
+
214
420
  @overload
215
421
  def __add__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
422
+
216
423
  @overload
217
424
  def __add__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
425
+
218
426
  @overload
219
427
  def __add__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
428
+
220
429
  @overload
221
430
  def __add__(
222
431
  self: "ASyncFuture[Decimal]", other: Decimal
223
432
  ) -> "ASyncFuture[Decimal]": ...
433
+
224
434
  @overload
225
435
  def __add__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]": ...
436
+
226
437
  @overload
227
438
  def __add__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]": ...
439
+
228
440
  @overload
229
441
  def __add__(
230
442
  self: "ASyncFuture[int]", other: Awaitable[int]
231
443
  ) -> "ASyncFuture[int]": ...
444
+
232
445
  @overload
233
446
  def __add__(
234
447
  self: "ASyncFuture[float]", other: Awaitable[float]
235
448
  ) -> "ASyncFuture[float]": ...
449
+
236
450
  @overload
237
451
  def __add__(
238
452
  self: "ASyncFuture[float]", other: Awaitable[int]
239
453
  ) -> "ASyncFuture[float]": ...
454
+
240
455
  @overload
241
456
  def __add__(
242
457
  self: "ASyncFuture[int]", other: Awaitable[float]
243
458
  ) -> "ASyncFuture[float]": ...
459
+
244
460
  @overload
245
461
  def __add__(
246
462
  self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
247
463
  ) -> "ASyncFuture[Decimal]": ...
464
+
248
465
  @overload
249
466
  def __add__(
250
467
  self: "ASyncFuture[Decimal]", other: Awaitable[int]
251
468
  ) -> "ASyncFuture[Decimal]": ...
469
+
252
470
  @overload
253
471
  def __add__(
254
472
  self: "ASyncFuture[int]", other: Awaitable[Decimal]
255
473
  ) -> "ASyncFuture[Decimal]": ...
474
+
256
475
  def __add__(self, other: MetaNumeric) -> "ASyncFuture":
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
+ """
257
492
  return ASyncFuture(
258
493
  self.__add(other), dependencies=self.__list_dependencies(other)
259
494
  )
260
495
 
261
496
  @overload
262
497
  def __sub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
498
+
263
499
  @overload
264
500
  def __sub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
501
+
265
502
  @overload
266
503
  def __sub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
504
+
267
505
  @overload
268
506
  def __sub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
507
+
269
508
  @overload
270
509
  def __sub__(
271
510
  self: "ASyncFuture[Decimal]", other: Decimal
272
511
  ) -> "ASyncFuture[Decimal]": ...
512
+
273
513
  @overload
274
514
  def __sub__(self: "ASyncFuture[Decimal]", other: int) -> "ASyncFuture[Decimal]": ...
515
+
275
516
  @overload
276
517
  def __sub__(self: "ASyncFuture[int]", other: Decimal) -> "ASyncFuture[Decimal]": ...
518
+
277
519
  @overload
278
520
  def __sub__(
279
521
  self: "ASyncFuture[int]", other: Awaitable[int]
280
522
  ) -> "ASyncFuture[int]": ...
523
+
281
524
  @overload
282
525
  def __sub__(
283
526
  self: "ASyncFuture[float]", other: Awaitable[float]
284
527
  ) -> "ASyncFuture[float]": ...
528
+
285
529
  @overload
286
530
  def __sub__(
287
531
  self: "ASyncFuture[float]", other: Awaitable[int]
288
532
  ) -> "ASyncFuture[float]": ...
533
+
289
534
  @overload
290
535
  def __sub__(
291
536
  self: "ASyncFuture[int]", other: Awaitable[float]
292
537
  ) -> "ASyncFuture[float]": ...
538
+
293
539
  @overload
294
540
  def __sub__(
295
541
  self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
296
542
  ) -> "ASyncFuture[Decimal]": ...
543
+
297
544
  @overload
298
545
  def __sub__(
299
546
  self: "ASyncFuture[Decimal]", other: Awaitable[int]
300
547
  ) -> "ASyncFuture[Decimal]": ...
548
+
301
549
  @overload
302
550
  def __sub__(
303
551
  self: "ASyncFuture[int]", other: Awaitable[Decimal]
304
552
  ) -> "ASyncFuture[Decimal]": ...
553
+
305
554
  def __sub__(self, other: MetaNumeric) -> "ASyncFuture":
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
+ """
306
571
  return ASyncFuture(
307
572
  self.__sub(other), dependencies=self.__list_dependencies(other)
308
573
  )
309
574
 
310
575
  def __mul__(self, other) -> "ASyncFuture":
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
+ """
311
592
  return ASyncFuture(
312
593
  self.__mul(other), dependencies=self.__list_dependencies(other)
313
594
  )
314
595
 
315
596
  def __pow__(self, other) -> "ASyncFuture":
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
+ """
316
613
  return ASyncFuture(
317
614
  self.__pow(other), dependencies=self.__list_dependencies(other)
318
615
  )
319
616
 
320
617
  def __truediv__(self, other) -> "ASyncFuture":
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
+ """
321
634
  return ASyncFuture(
322
635
  self.__truediv(other), dependencies=self.__list_dependencies(other)
323
636
  )
324
637
 
325
638
  def __floordiv__(self, other) -> "ASyncFuture":
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
+ """
326
655
  return ASyncFuture(
327
656
  self.__floordiv(other), dependencies=self.__list_dependencies(other)
328
657
  )
329
658
 
330
659
  def __pow__(self, other) -> "ASyncFuture":
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
+ """
331
676
  return ASyncFuture(
332
677
  self.__pow(other), dependencies=self.__list_dependencies(other)
333
678
  )
334
679
 
335
680
  @overload
336
681
  def __radd__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
682
+
337
683
  @overload
338
684
  def __radd__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
685
+
339
686
  @overload
340
687
  def __radd__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
688
+
341
689
  @overload
342
690
  def __radd__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
691
+
343
692
  @overload
344
693
  def __radd__(
345
694
  self: "ASyncFuture[Decimal]", other: Decimal
346
695
  ) -> "ASyncFuture[Decimal]": ...
696
+
347
697
  @overload
348
698
  def __radd__(
349
699
  self: "ASyncFuture[Decimal]", other: int
350
700
  ) -> "ASyncFuture[Decimal]": ...
701
+
351
702
  @overload
352
703
  def __radd__(
353
704
  self: "ASyncFuture[int]", other: Decimal
354
705
  ) -> "ASyncFuture[Decimal]": ...
706
+
355
707
  @overload
356
708
  def __radd__(
357
709
  self: "ASyncFuture[int]", other: Awaitable[int]
358
710
  ) -> "ASyncFuture[int]": ...
711
+
359
712
  @overload
360
713
  def __radd__(
361
714
  self: "ASyncFuture[float]", other: Awaitable[float]
362
715
  ) -> "ASyncFuture[float]": ...
716
+
363
717
  @overload
364
718
  def __radd__(
365
719
  self: "ASyncFuture[float]", other: Awaitable[int]
366
720
  ) -> "ASyncFuture[float]": ...
721
+
367
722
  @overload
368
723
  def __radd__(
369
724
  self: "ASyncFuture[int]", other: Awaitable[float]
370
725
  ) -> "ASyncFuture[float]": ...
726
+
371
727
  @overload
372
728
  def __radd__(
373
729
  self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
374
730
  ) -> "ASyncFuture[Decimal]": ...
731
+
375
732
  @overload
376
733
  def __radd__(
377
734
  self: "ASyncFuture[Decimal]", other: Awaitable[int]
378
735
  ) -> "ASyncFuture[Decimal]": ...
736
+
379
737
  @overload
380
738
  def __radd__(
381
739
  self: "ASyncFuture[int]", other: Awaitable[Decimal]
382
740
  ) -> "ASyncFuture[Decimal]": ...
741
+
383
742
  def __radd__(self, other) -> "ASyncFuture":
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
+ """
384
758
  return ASyncFuture(
385
759
  self.__radd(other), dependencies=self.__list_dependencies(other)
386
760
  )
387
761
 
388
762
  @overload
389
763
  def __rsub__(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
764
+
390
765
  @overload
391
766
  def __rsub__(self: "ASyncFuture[float]", other: float) -> "ASyncFuture[float]": ...
767
+
392
768
  @overload
393
769
  def __rsub__(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
770
+
394
771
  @overload
395
772
  def __rsub__(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
773
+
396
774
  @overload
397
775
  def __rsub__(
398
776
  self: "ASyncFuture[Decimal]", other: Decimal
399
777
  ) -> "ASyncFuture[Decimal]": ...
778
+
400
779
  @overload
401
780
  def __rsub__(
402
781
  self: "ASyncFuture[Decimal]", other: int
403
782
  ) -> "ASyncFuture[Decimal]": ...
783
+
404
784
  @overload
405
785
  def __rsub__(
406
786
  self: "ASyncFuture[int]", other: Decimal
407
787
  ) -> "ASyncFuture[Decimal]": ...
788
+
408
789
  @overload
409
790
  def __rsub__(
410
791
  self: "ASyncFuture[int]", other: Awaitable[int]
411
792
  ) -> "ASyncFuture[int]": ...
793
+
412
794
  @overload
413
795
  def __rsub__(
414
796
  self: "ASyncFuture[float]", other: Awaitable[float]
415
797
  ) -> "ASyncFuture[float]": ...
798
+
416
799
  @overload
417
800
  def __rsub__(
418
801
  self: "ASyncFuture[float]", other: Awaitable[int]
419
802
  ) -> "ASyncFuture[float]": ...
803
+
420
804
  @overload
421
805
  def __rsub__(
422
806
  self: "ASyncFuture[int]", other: Awaitable[float]
423
807
  ) -> "ASyncFuture[float]": ...
808
+
424
809
  @overload
425
810
  def __rsub__(
426
811
  self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
427
812
  ) -> "ASyncFuture[Decimal]": ...
813
+
428
814
  @overload
429
815
  def __rsub__(
430
816
  self: "ASyncFuture[Decimal]", other: Awaitable[int]
431
817
  ) -> "ASyncFuture[Decimal]": ...
818
+
432
819
  @overload
433
820
  def __rsub__(
434
821
  self: "ASyncFuture[int]", other: Awaitable[Decimal]
435
822
  ) -> "ASyncFuture[Decimal]": ...
823
+
436
824
  def __rsub__(self, other) -> "ASyncFuture":
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
+ """
437
840
  return ASyncFuture(
438
841
  self.__rsub(other), dependencies=self.__list_dependencies(other)
439
842
  )
440
843
 
441
844
  def __rmul__(self, other) -> "ASyncFuture":
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
+ """
442
860
  return ASyncFuture(
443
861
  self.__rmul(other), dependencies=self.__list_dependencies(other)
444
862
  )
445
863
 
446
864
  def __rtruediv__(self, other) -> "ASyncFuture":
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
+ """
447
880
  return ASyncFuture(
448
881
  self.__rtruediv(other), dependencies=self.__list_dependencies(other)
449
882
  )
450
883
 
451
884
  def __rfloordiv__(self, other) -> "ASyncFuture":
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
+ """
452
900
  return ASyncFuture(
453
901
  self.__rfloordiv(other), dependencies=self.__list_dependencies(other)
454
902
  )
455
903
 
456
904
  def __rpow__(self, other) -> "ASyncFuture":
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
+ """
457
920
  return ASyncFuture(
458
921
  self.__rpow(other), dependencies=self.__list_dependencies(other)
459
922
  )
460
923
 
461
924
  def __eq__(self, other) -> "ASyncFuture":
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
+ """
462
941
  return bool(
463
942
  ASyncFuture(self.__eq(other), dependencies=self.__list_dependencies(other))
464
943
  )
465
944
 
466
945
  def __gt__(self, other) -> "ASyncFuture":
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
+ """
467
962
  return ASyncFuture(
468
963
  self.__gt(other), dependencies=self.__list_dependencies(other)
469
964
  )
470
965
 
471
966
  def __ge__(self, other) -> "ASyncFuture":
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
+ """
472
983
  return ASyncFuture(
473
984
  self.__ge(other), dependencies=self.__list_dependencies(other)
474
985
  )
475
986
 
476
987
  def __lt__(self, other) -> "ASyncFuture":
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
+ """
477
1004
  return ASyncFuture(
478
1005
  self.__lt(other), dependencies=self.__list_dependencies(other)
479
1006
  )
480
1007
 
481
1008
  def __le__(self, other) -> "ASyncFuture":
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
+ """
482
1025
  return ASyncFuture(
483
1026
  self.__le(other), dependencies=self.__list_dependencies(other)
484
1027
  )
@@ -487,108 +1030,136 @@ class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
487
1030
 
488
1031
  @overload
489
1032
  async def __add(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
1033
+
490
1034
  @overload
491
1035
  async def __add(
492
1036
  self: "ASyncFuture[float]", other: float
493
1037
  ) -> "ASyncFuture[float]": ...
1038
+
494
1039
  @overload
495
1040
  async def __add(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
1041
+
496
1042
  @overload
497
1043
  async def __add(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
1044
+
498
1045
  @overload
499
1046
  async def __add(
500
1047
  self: "ASyncFuture[Decimal]", other: Decimal
501
1048
  ) -> "ASyncFuture[Decimal]": ...
1049
+
502
1050
  @overload
503
1051
  async def __add(
504
1052
  self: "ASyncFuture[Decimal]", other: int
505
1053
  ) -> "ASyncFuture[Decimal]": ...
1054
+
506
1055
  @overload
507
1056
  async def __add(
508
1057
  self: "ASyncFuture[int]", other: Decimal
509
1058
  ) -> "ASyncFuture[Decimal]": ...
1059
+
510
1060
  @overload
511
1061
  async def __add(
512
1062
  self: "ASyncFuture[int]", other: Awaitable[int]
513
1063
  ) -> "ASyncFuture[int]": ...
1064
+
514
1065
  @overload
515
1066
  async def __add(
516
1067
  self: "ASyncFuture[float]", other: Awaitable[float]
517
1068
  ) -> "ASyncFuture[float]": ...
1069
+
518
1070
  @overload
519
1071
  async def __add(
520
1072
  self: "ASyncFuture[float]", other: Awaitable[int]
521
1073
  ) -> "ASyncFuture[float]": ...
1074
+
522
1075
  @overload
523
1076
  async def __add(
524
1077
  self: "ASyncFuture[int]", other: Awaitable[float]
525
1078
  ) -> "ASyncFuture[float]": ...
1079
+
526
1080
  @overload
527
1081
  async def __add(
528
1082
  self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
529
1083
  ) -> "ASyncFuture[Decimal]": ...
1084
+
530
1085
  @overload
531
1086
  async def __add(
532
1087
  self: "ASyncFuture[Decimal]", other: Awaitable[int]
533
1088
  ) -> "ASyncFuture[Decimal]": ...
1089
+
534
1090
  @overload
535
1091
  async def __add(
536
1092
  self: "ASyncFuture[int]", other: Awaitable[Decimal]
537
1093
  ) -> "ASyncFuture[Decimal]": ...
1094
+
538
1095
  async def __add(self, other) -> "Any":
539
1096
  a, b = await _gather_check_and_materialize(self, other)
540
1097
  return a + b
541
1098
 
542
1099
  @overload
543
1100
  async def __sub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
1101
+
544
1102
  @overload
545
1103
  async def __sub(
546
1104
  self: "ASyncFuture[float]", other: float
547
1105
  ) -> "ASyncFuture[float]": ...
1106
+
548
1107
  @overload
549
1108
  async def __sub(self: "ASyncFuture[float]", other: int) -> "ASyncFuture[float]": ...
1109
+
550
1110
  @overload
551
1111
  async def __sub(self: "ASyncFuture[int]", other: float) -> "ASyncFuture[float]": ...
1112
+
552
1113
  @overload
553
1114
  async def __sub(
554
1115
  self: "ASyncFuture[Decimal]", other: Decimal
555
1116
  ) -> "ASyncFuture[Decimal]": ...
1117
+
556
1118
  @overload
557
1119
  async def __sub(
558
1120
  self: "ASyncFuture[Decimal]", other: int
559
1121
  ) -> "ASyncFuture[Decimal]": ...
1122
+
560
1123
  @overload
561
1124
  async def __sub(
562
1125
  self: "ASyncFuture[int]", other: Decimal
563
1126
  ) -> "ASyncFuture[Decimal]": ...
1127
+
564
1128
  @overload
565
1129
  async def __sub(
566
1130
  self: "ASyncFuture[int]", other: Awaitable[int]
567
1131
  ) -> "ASyncFuture[int]": ...
1132
+
568
1133
  @overload
569
1134
  async def __sub(
570
1135
  self: "ASyncFuture[float]", other: Awaitable[float]
571
1136
  ) -> "ASyncFuture[float]": ...
1137
+
572
1138
  @overload
573
1139
  async def __sub(
574
1140
  self: "ASyncFuture[float]", other: Awaitable[int]
575
1141
  ) -> "ASyncFuture[float]": ...
1142
+
576
1143
  @overload
577
1144
  async def __sub(
578
1145
  self: "ASyncFuture[int]", other: Awaitable[float]
579
1146
  ) -> "ASyncFuture[float]": ...
1147
+
580
1148
  @overload
581
1149
  async def __sub(
582
1150
  self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
583
1151
  ) -> "ASyncFuture[Decimal]": ...
1152
+
584
1153
  @overload
585
1154
  async def __sub(
586
1155
  self: "ASyncFuture[Decimal]", other: Awaitable[int]
587
1156
  ) -> "ASyncFuture[Decimal]": ...
1157
+
588
1158
  @overload
589
1159
  async def __sub(
590
1160
  self: "ASyncFuture[int]", other: Awaitable[Decimal]
591
1161
  ) -> "ASyncFuture[Decimal]": ...
1162
+
592
1163
  async def __sub(self, other) -> "Any":
593
1164
  a, b = await _gather_check_and_materialize(self, other)
594
1165
  return a - b
@@ -612,116 +1183,144 @@ class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
612
1183
  # rMaths
613
1184
  @overload
614
1185
  async def __radd(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
1186
+
615
1187
  @overload
616
1188
  async def __radd(
617
1189
  self: "ASyncFuture[float]", other: float
618
1190
  ) -> "ASyncFuture[float]": ...
1191
+
619
1192
  @overload
620
1193
  async def __radd(
621
1194
  self: "ASyncFuture[float]", other: int
622
1195
  ) -> "ASyncFuture[float]": ...
1196
+
623
1197
  @overload
624
1198
  async def __radd(
625
1199
  self: "ASyncFuture[int]", other: float
626
1200
  ) -> "ASyncFuture[float]": ...
1201
+
627
1202
  @overload
628
1203
  async def __radd(
629
1204
  self: "ASyncFuture[Decimal]", other: Decimal
630
1205
  ) -> "ASyncFuture[Decimal]": ...
1206
+
631
1207
  @overload
632
1208
  async def __radd(
633
1209
  self: "ASyncFuture[Decimal]", other: int
634
1210
  ) -> "ASyncFuture[Decimal]": ...
1211
+
635
1212
  @overload
636
1213
  async def __radd(
637
1214
  self: "ASyncFuture[int]", other: Decimal
638
1215
  ) -> "ASyncFuture[Decimal]": ...
1216
+
639
1217
  @overload
640
1218
  async def __radd(
641
1219
  self: "ASyncFuture[int]", other: Awaitable[int]
642
1220
  ) -> "ASyncFuture[int]": ...
1221
+
643
1222
  @overload
644
1223
  async def __radd(
645
1224
  self: "ASyncFuture[float]", other: Awaitable[float]
646
1225
  ) -> "ASyncFuture[float]": ...
1226
+
647
1227
  @overload
648
1228
  async def __radd(
649
1229
  self: "ASyncFuture[float]", other: Awaitable[int]
650
1230
  ) -> "ASyncFuture[float]": ...
1231
+
651
1232
  @overload
652
1233
  async def __radd(
653
1234
  self: "ASyncFuture[int]", other: Awaitable[float]
654
1235
  ) -> "ASyncFuture[float]": ...
1236
+
655
1237
  @overload
656
1238
  async def __radd(
657
1239
  self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
658
1240
  ) -> "ASyncFuture[Decimal]": ...
1241
+
659
1242
  @overload
660
1243
  async def __radd(
661
1244
  self: "ASyncFuture[Decimal]", other: Awaitable[int]
662
1245
  ) -> "ASyncFuture[Decimal]": ...
1246
+
663
1247
  @overload
664
1248
  async def __radd(
665
1249
  self: "ASyncFuture[int]", other: Awaitable[Decimal]
666
1250
  ) -> "ASyncFuture[Decimal]": ...
1251
+
667
1252
  async def __radd(self, other) -> "Any":
668
1253
  a, b = await _gather_check_and_materialize(other, self)
669
1254
  return a + b
670
1255
 
671
1256
  @overload
672
1257
  async def __rsub(self: "ASyncFuture[int]", other: int) -> "ASyncFuture[int]": ...
1258
+
673
1259
  @overload
674
1260
  async def __rsub(
675
1261
  self: "ASyncFuture[float]", other: float
676
1262
  ) -> "ASyncFuture[float]": ...
1263
+
677
1264
  @overload
678
1265
  async def __rsub(
679
1266
  self: "ASyncFuture[float]", other: int
680
1267
  ) -> "ASyncFuture[float]": ...
1268
+
681
1269
  @overload
682
1270
  async def __rsub(
683
1271
  self: "ASyncFuture[int]", other: float
684
1272
  ) -> "ASyncFuture[float]": ...
1273
+
685
1274
  @overload
686
1275
  async def __rsub(
687
1276
  self: "ASyncFuture[Decimal]", other: Decimal
688
1277
  ) -> "ASyncFuture[Decimal]": ...
1278
+
689
1279
  @overload
690
1280
  async def __rsub(
691
1281
  self: "ASyncFuture[Decimal]", other: int
692
1282
  ) -> "ASyncFuture[Decimal]": ...
1283
+
693
1284
  @overload
694
1285
  async def __rsub(
695
1286
  self: "ASyncFuture[int]", other: Decimal
696
1287
  ) -> "ASyncFuture[Decimal]": ...
1288
+
697
1289
  @overload
698
1290
  async def __rsub(
699
1291
  self: "ASyncFuture[int]", other: Awaitable[int]
700
1292
  ) -> "ASyncFuture[int]": ...
1293
+
701
1294
  @overload
702
1295
  async def __rsub(
703
1296
  self: "ASyncFuture[float]", other: Awaitable[float]
704
1297
  ) -> "ASyncFuture[float]": ...
1298
+
705
1299
  @overload
706
1300
  async def __rsub(
707
1301
  self: "ASyncFuture[float]", other: Awaitable[int]
708
1302
  ) -> "ASyncFuture[float]": ...
1303
+
709
1304
  @overload
710
1305
  async def __rsub(
711
1306
  self: "ASyncFuture[int]", other: Awaitable[float]
712
1307
  ) -> "ASyncFuture[float]": ...
1308
+
713
1309
  @overload
714
1310
  async def __rsub(
715
1311
  self: "ASyncFuture[Decimal]", other: Awaitable[Decimal]
716
1312
  ) -> "ASyncFuture[Decimal]": ...
1313
+
717
1314
  @overload
718
1315
  async def __rsub(
719
1316
  self: "ASyncFuture[Decimal]", other: Awaitable[int]
720
1317
  ) -> "ASyncFuture[Decimal]": ...
1318
+
721
1319
  @overload
722
1320
  async def __rsub(
723
1321
  self: "ASyncFuture[int]", other: Awaitable[Decimal]
724
1322
  ) -> "ASyncFuture[Decimal]": ...
1323
+
725
1324
  async def __rsub(self, other) -> "Any":
726
1325
  a, b = await _gather_check_and_materialize(other, self)
727
1326
  return a - b
@@ -820,7 +1419,14 @@ class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
820
1419
  @property
821
1420
  def __dependants__(self) -> Set["ASyncFuture"]:
822
1421
  """
823
- Returns the set of dependants for this ASyncFuture, including nested dependants.
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
824
1430
  """
825
1431
  dependants = set()
826
1432
  for dep in self.__dependants:
@@ -831,7 +1437,14 @@ class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
831
1437
  @property
832
1438
  def __dependencies__(self) -> Set["ASyncFuture"]:
833
1439
  """
834
- Returns the set of dependencies for this ASyncFuture, including nested dependencies.
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
835
1448
  """
836
1449
  dependencies = set()
837
1450
  for dep in self.__dependencies:
@@ -852,7 +1465,22 @@ class ASyncFuture(concurrent.futures.Future, Awaitable[T]):
852
1465
  @final
853
1466
  class _ASyncFutureWrappedFn(Callable[P, ASyncFuture[T]]):
854
1467
  """
855
- A callable class to wrap functions and return ASyncFuture objects.
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.
856
1484
  """
857
1485
 
858
1486
  __slots__ = "callable", "wrapped", "_callable_name"
@@ -891,17 +1519,31 @@ class _ASyncFutureWrappedFn(Callable[P, ASyncFuture[T]]):
891
1519
  def __get__(
892
1520
  self, instance: I, owner: Type[I]
893
1521
  ) -> Union[Self, "_ASyncFutureInstanceMethod[I, P, T]"]:
894
- if owner is None:
895
- return self
896
- else:
897
- return _ASyncFutureInstanceMethod(self, instance)
1522
+ return self if owner is None else _ASyncFutureInstanceMethod(self, instance)
898
1523
 
899
1524
 
900
1525
  @final
901
1526
  class _ASyncFutureInstanceMethod(Generic[I, P, T]):
902
1527
  # NOTE: probably could just replace this with functools.partial
903
1528
  """
904
- A class to handle instance methods wrapped as ASyncFuture.
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.
905
1547
  """
906
1548
 
907
1549
  __module__: str
@@ -929,7 +1571,7 @@ class _ASyncFutureInstanceMethod(Generic[I, P, T]):
929
1571
  self,
930
1572
  wrapper: _ASyncFutureWrappedFn[P, T],
931
1573
  instance: I,
932
- ) -> None:
1574
+ ) -> None: # sourcery skip: use-contextlib-suppress
933
1575
  try:
934
1576
  self.__module__ = wrapper.__module__
935
1577
  except AttributeError: