ez-a-sync 0.33.4__cp313-cp313-musllinux_1_2_i686.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.
Files changed (177) hide show
  1. a_sync/ENVIRONMENT_VARIABLES.py +42 -0
  2. a_sync/__init__.pxd +2 -0
  3. a_sync/__init__.py +145 -0
  4. a_sync/_smart.c +22830 -0
  5. a_sync/_smart.cpython-313-i386-linux-musl.so +0 -0
  6. a_sync/_smart.pxd +2 -0
  7. a_sync/_smart.pyi +202 -0
  8. a_sync/_smart.pyx +674 -0
  9. a_sync/_typing.py +258 -0
  10. a_sync/a_sync/__init__.py +60 -0
  11. a_sync/a_sync/_descriptor.c +20537 -0
  12. a_sync/a_sync/_descriptor.cpython-313-i386-linux-musl.so +0 -0
  13. a_sync/a_sync/_descriptor.pyi +33 -0
  14. a_sync/a_sync/_descriptor.pyx +422 -0
  15. a_sync/a_sync/_flags.c +6082 -0
  16. a_sync/a_sync/_flags.cpython-313-i386-linux-musl.so +0 -0
  17. a_sync/a_sync/_flags.pxd +3 -0
  18. a_sync/a_sync/_flags.pyx +92 -0
  19. a_sync/a_sync/_helpers.c +14529 -0
  20. a_sync/a_sync/_helpers.cpython-313-i386-linux-musl.so +0 -0
  21. a_sync/a_sync/_helpers.pxd +3 -0
  22. a_sync/a_sync/_helpers.pyi +10 -0
  23. a_sync/a_sync/_helpers.pyx +167 -0
  24. a_sync/a_sync/_kwargs.c +12202 -0
  25. a_sync/a_sync/_kwargs.cpython-313-i386-linux-musl.so +0 -0
  26. a_sync/a_sync/_kwargs.pxd +2 -0
  27. a_sync/a_sync/_kwargs.pyx +64 -0
  28. a_sync/a_sync/_meta.py +210 -0
  29. a_sync/a_sync/abstract.c +12420 -0
  30. a_sync/a_sync/abstract.cpython-313-i386-linux-musl.so +0 -0
  31. a_sync/a_sync/abstract.pyi +141 -0
  32. a_sync/a_sync/abstract.pyx +221 -0
  33. a_sync/a_sync/base.c +14940 -0
  34. a_sync/a_sync/base.cpython-313-i386-linux-musl.so +0 -0
  35. a_sync/a_sync/base.pyi +60 -0
  36. a_sync/a_sync/base.pyx +271 -0
  37. a_sync/a_sync/config.py +168 -0
  38. a_sync/a_sync/decorator.py +651 -0
  39. a_sync/a_sync/flags.c +5272 -0
  40. a_sync/a_sync/flags.cpython-313-i386-linux-musl.so +0 -0
  41. a_sync/a_sync/flags.pxd +72 -0
  42. a_sync/a_sync/flags.pyi +74 -0
  43. a_sync/a_sync/flags.pyx +72 -0
  44. a_sync/a_sync/function.c +37856 -0
  45. a_sync/a_sync/function.cpython-313-i386-linux-musl.so +0 -0
  46. a_sync/a_sync/function.pxd +28 -0
  47. a_sync/a_sync/function.pyi +571 -0
  48. a_sync/a_sync/function.pyx +1381 -0
  49. a_sync/a_sync/method.c +29662 -0
  50. a_sync/a_sync/method.cpython-313-i386-linux-musl.so +0 -0
  51. a_sync/a_sync/method.pxd +9 -0
  52. a_sync/a_sync/method.pyi +523 -0
  53. a_sync/a_sync/method.pyx +1023 -0
  54. a_sync/a_sync/modifiers/__init__.pxd +1 -0
  55. a_sync/a_sync/modifiers/__init__.py +101 -0
  56. a_sync/a_sync/modifiers/cache/__init__.py +160 -0
  57. a_sync/a_sync/modifiers/cache/memory.py +165 -0
  58. a_sync/a_sync/modifiers/limiter.py +132 -0
  59. a_sync/a_sync/modifiers/manager.c +16157 -0
  60. a_sync/a_sync/modifiers/manager.cpython-313-i386-linux-musl.so +0 -0
  61. a_sync/a_sync/modifiers/manager.pxd +5 -0
  62. a_sync/a_sync/modifiers/manager.pyi +219 -0
  63. a_sync/a_sync/modifiers/manager.pyx +299 -0
  64. a_sync/a_sync/modifiers/semaphores.py +173 -0
  65. a_sync/a_sync/property.c +27268 -0
  66. a_sync/a_sync/property.cpython-313-i386-linux-musl.so +0 -0
  67. a_sync/a_sync/property.pyi +376 -0
  68. a_sync/a_sync/property.pyx +819 -0
  69. a_sync/a_sync/singleton.py +63 -0
  70. a_sync/aliases.py +3 -0
  71. a_sync/async_property/__init__.pxd +1 -0
  72. a_sync/async_property/__init__.py +1 -0
  73. a_sync/async_property/cached.c +20397 -0
  74. a_sync/async_property/cached.cpython-313-i386-linux-musl.so +0 -0
  75. a_sync/async_property/cached.pxd +10 -0
  76. a_sync/async_property/cached.pyi +45 -0
  77. a_sync/async_property/cached.pyx +178 -0
  78. a_sync/async_property/proxy.c +34662 -0
  79. a_sync/async_property/proxy.cpython-313-i386-linux-musl.so +0 -0
  80. a_sync/async_property/proxy.pxd +2 -0
  81. a_sync/async_property/proxy.pyi +124 -0
  82. a_sync/async_property/proxy.pyx +474 -0
  83. a_sync/asyncio/__init__.pxd +6 -0
  84. a_sync/asyncio/__init__.py +164 -0
  85. a_sync/asyncio/as_completed.c +18849 -0
  86. a_sync/asyncio/as_completed.cpython-313-i386-linux-musl.so +0 -0
  87. a_sync/asyncio/as_completed.pxd +8 -0
  88. a_sync/asyncio/as_completed.pyi +109 -0
  89. a_sync/asyncio/as_completed.pyx +269 -0
  90. a_sync/asyncio/create_task.c +15912 -0
  91. a_sync/asyncio/create_task.cpython-313-i386-linux-musl.so +0 -0
  92. a_sync/asyncio/create_task.pxd +2 -0
  93. a_sync/asyncio/create_task.pyi +51 -0
  94. a_sync/asyncio/create_task.pyx +271 -0
  95. a_sync/asyncio/gather.c +16687 -0
  96. a_sync/asyncio/gather.cpython-313-i386-linux-musl.so +0 -0
  97. a_sync/asyncio/gather.pyi +107 -0
  98. a_sync/asyncio/gather.pyx +218 -0
  99. a_sync/asyncio/igather.c +13080 -0
  100. a_sync/asyncio/igather.cpython-313-i386-linux-musl.so +0 -0
  101. a_sync/asyncio/igather.pxd +1 -0
  102. a_sync/asyncio/igather.pyi +8 -0
  103. a_sync/asyncio/igather.pyx +183 -0
  104. a_sync/asyncio/sleep.c +9601 -0
  105. a_sync/asyncio/sleep.cpython-313-i386-linux-musl.so +0 -0
  106. a_sync/asyncio/sleep.pyi +14 -0
  107. a_sync/asyncio/sleep.pyx +49 -0
  108. a_sync/debugging.c +15370 -0
  109. a_sync/debugging.cpython-313-i386-linux-musl.so +0 -0
  110. a_sync/debugging.pyi +76 -0
  111. a_sync/debugging.pyx +107 -0
  112. a_sync/exceptions.c +13320 -0
  113. a_sync/exceptions.cpython-313-i386-linux-musl.so +0 -0
  114. a_sync/exceptions.pyi +376 -0
  115. a_sync/exceptions.pyx +446 -0
  116. a_sync/executor.py +619 -0
  117. a_sync/functools.c +12746 -0
  118. a_sync/functools.cpython-313-i386-linux-musl.so +0 -0
  119. a_sync/functools.pxd +7 -0
  120. a_sync/functools.pyi +33 -0
  121. a_sync/functools.pyx +139 -0
  122. a_sync/future.py +1497 -0
  123. a_sync/iter.c +37279 -0
  124. a_sync/iter.cpython-313-i386-linux-musl.so +0 -0
  125. a_sync/iter.pxd +11 -0
  126. a_sync/iter.pyi +370 -0
  127. a_sync/iter.pyx +981 -0
  128. a_sync/primitives/__init__.pxd +1 -0
  129. a_sync/primitives/__init__.py +53 -0
  130. a_sync/primitives/_debug.c +15765 -0
  131. a_sync/primitives/_debug.cpython-313-i386-linux-musl.so +0 -0
  132. a_sync/primitives/_debug.pxd +12 -0
  133. a_sync/primitives/_debug.pyi +52 -0
  134. a_sync/primitives/_debug.pyx +223 -0
  135. a_sync/primitives/_loggable.c +11538 -0
  136. a_sync/primitives/_loggable.cpython-313-i386-linux-musl.so +0 -0
  137. a_sync/primitives/_loggable.pxd +4 -0
  138. a_sync/primitives/_loggable.pyi +66 -0
  139. a_sync/primitives/_loggable.pyx +102 -0
  140. a_sync/primitives/locks/__init__.pxd +8 -0
  141. a_sync/primitives/locks/__init__.py +17 -0
  142. a_sync/primitives/locks/counter.c +17938 -0
  143. a_sync/primitives/locks/counter.cpython-313-i386-linux-musl.so +0 -0
  144. a_sync/primitives/locks/counter.pxd +12 -0
  145. a_sync/primitives/locks/counter.pyi +151 -0
  146. a_sync/primitives/locks/counter.pyx +267 -0
  147. a_sync/primitives/locks/event.c +17072 -0
  148. a_sync/primitives/locks/event.cpython-313-i386-linux-musl.so +0 -0
  149. a_sync/primitives/locks/event.pxd +22 -0
  150. a_sync/primitives/locks/event.pyi +43 -0
  151. a_sync/primitives/locks/event.pyx +185 -0
  152. a_sync/primitives/locks/prio_semaphore.c +25635 -0
  153. a_sync/primitives/locks/prio_semaphore.cpython-313-i386-linux-musl.so +0 -0
  154. a_sync/primitives/locks/prio_semaphore.pxd +25 -0
  155. a_sync/primitives/locks/prio_semaphore.pyi +217 -0
  156. a_sync/primitives/locks/prio_semaphore.pyx +597 -0
  157. a_sync/primitives/locks/semaphore.c +26553 -0
  158. a_sync/primitives/locks/semaphore.cpython-313-i386-linux-musl.so +0 -0
  159. a_sync/primitives/locks/semaphore.pxd +21 -0
  160. a_sync/primitives/locks/semaphore.pyi +197 -0
  161. a_sync/primitives/locks/semaphore.pyx +454 -0
  162. a_sync/primitives/queue.py +1026 -0
  163. a_sync/py.typed +0 -0
  164. a_sync/sphinx/__init__.py +3 -0
  165. a_sync/sphinx/ext.py +289 -0
  166. a_sync/task.py +934 -0
  167. a_sync/utils/__init__.py +105 -0
  168. a_sync/utils/iterators.py +297 -0
  169. a_sync/utils/repr.c +15866 -0
  170. a_sync/utils/repr.cpython-313-i386-linux-musl.so +0 -0
  171. a_sync/utils/repr.pyi +2 -0
  172. a_sync/utils/repr.pyx +73 -0
  173. ez_a_sync-0.33.4.dist-info/METADATA +368 -0
  174. ez_a_sync-0.33.4.dist-info/RECORD +177 -0
  175. ez_a_sync-0.33.4.dist-info/WHEEL +5 -0
  176. ez_a_sync-0.33.4.dist-info/licenses/LICENSE.txt +17 -0
  177. ez_a_sync-0.33.4.dist-info/top_level.txt +1 -0
@@ -0,0 +1,8 @@
1
+ cdef object as_completed_mapping(
2
+ object mapping,
3
+ unsigned int timeout,
4
+ bint return_exceptions,
5
+ bint aiter,
6
+ bint tqdm,
7
+ dict tqdm_kwargs,
8
+ )
@@ -0,0 +1,109 @@
1
+ """
2
+ This module extends Python's :func:`asyncio.as_completed` with additional functionality.
3
+ """
4
+
5
+ from a_sync._typing import *
6
+ from a_sync.iter import ASyncIterator
7
+
8
+ __all__ = ["as_completed"]
9
+
10
+ class tqdm_asyncio:
11
+ @staticmethod
12
+ def as_completed(*args, **kwargs) -> None: ...
13
+
14
+ @overload
15
+ def as_completed(
16
+ fs: Iterable[Awaitable[T]],
17
+ *,
18
+ timeout: Optional[float] = None,
19
+ return_exceptions: bool = False,
20
+ aiter: Literal[False] = False,
21
+ tqdm: bool = False,
22
+ **tqdm_kwargs: Any
23
+ ) -> Iterator[Coroutine[Any, Any, T]]: ...
24
+ @overload
25
+ def as_completed(
26
+ fs: Iterable[Awaitable[T]],
27
+ *,
28
+ timeout: Optional[float] = None,
29
+ return_exceptions: bool = False,
30
+ aiter: Literal[True] = True,
31
+ tqdm: bool = False,
32
+ **tqdm_kwargs: Any
33
+ ) -> ASyncIterator[T]: ...
34
+ @overload
35
+ def as_completed(
36
+ fs: Mapping[K, Awaitable[V]],
37
+ *,
38
+ timeout: Optional[float] = None,
39
+ return_exceptions: bool = False,
40
+ aiter: Literal[False] = False,
41
+ tqdm: bool = False,
42
+ **tqdm_kwargs: Any
43
+ ) -> Iterator[Coroutine[Any, Any, Tuple[K, V]]]: ...
44
+ @overload
45
+ def as_completed(
46
+ fs: Mapping[K, Awaitable[V]],
47
+ *,
48
+ timeout: Optional[float] = None,
49
+ return_exceptions: bool = False,
50
+ aiter: Literal[True] = True,
51
+ tqdm: bool = False,
52
+ **tqdm_kwargs: Any
53
+ ) -> ASyncIterator[Tuple[K, V]]: ...
54
+ def as_completed(
55
+ fs,
56
+ *,
57
+ timeout: Optional[float] = None,
58
+ return_exceptions: bool = False,
59
+ aiter: bool = False,
60
+ tqdm: bool = False,
61
+ **tqdm_kwargs: Any
62
+ ):
63
+ """
64
+ Concurrently awaits a list of awaitable objects or mappings of awaitables and returns an iterator of results.
65
+
66
+ This function extends Python's :func:`asyncio.as_completed`, providing additional features for mixed use cases of individual awaitable objects and mappings of awaitables.
67
+
68
+ Differences from :func:`asyncio.as_completed`:
69
+ - Uses type hints for use with static type checkers.
70
+ - Supports either individual awaitables or a k:v mapping of awaitables.
71
+ - Can be used as an async iterator which yields the result values using :class:`ASyncIterator`.
72
+ - Provides progress reporting using :mod:`tqdm` if 'tqdm' is set to True.
73
+
74
+ Note:
75
+ The `return_exceptions` parameter is used to wrap awaitables with exceptions if set to True, allowing exceptions to be returned as results instead of being raised.
76
+
77
+ Args:
78
+ fs: The awaitables to await concurrently. It can be a list of individual awaitables or a mapping of awaitables.
79
+ timeout: The maximum time, in seconds, to wait for the completion of awaitables. Defaults to None (no timeout).
80
+ return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
81
+ aiter: If True, returns an async iterator of results using :class:`ASyncIterator`. Defaults to False.
82
+ tqdm: If True, enables progress reporting using :mod:`tqdm`. Defaults to False.
83
+ **tqdm_kwargs: Additional keyword arguments for :mod:`tqdm` if progress reporting is enabled.
84
+
85
+ Examples:
86
+ Awaiting individual awaitables:
87
+
88
+ >>> awaitables = [async_function1(), async_function2()]
89
+ >>> for coro in as_completed(awaitables):
90
+ ... val = await coro
91
+ ... ...
92
+
93
+ >>> async for val in as_completed(awaitables, aiter=True):
94
+ ... ...
95
+
96
+ Awaiting mappings of awaitables:
97
+
98
+ >>> mapping = {'key1': async_function1(), 'key2': async_function2()}
99
+ >>> for coro in as_completed(mapping):
100
+ ... k, v = await coro
101
+ ... ...
102
+
103
+ >>> async for k, v in as_completed(mapping, aiter=True):
104
+ ... ...
105
+
106
+ See Also:
107
+ - :func:`asyncio.as_completed`
108
+ - :class:`ASyncIterator`
109
+ """
@@ -0,0 +1,269 @@
1
+ """
2
+ This module extends Python's :func:`asyncio.as_completed` with additional functionality.
3
+ """
4
+
5
+ import asyncio
6
+ from typing import (Any, AsyncIterator, Awaitable, Coroutine, Iterable,
7
+ Iterator, Literal, Mapping, Optional, Tuple, Union,
8
+ overload)
9
+
10
+ from a_sync import iter
11
+ from a_sync._typing import K, T, V
12
+
13
+
14
+ # cdef asyncio
15
+ cdef object _as_completed = asyncio.as_completed
16
+ del asyncio
17
+
18
+ # cdef tqdm
19
+ try:
20
+ from tqdm.asyncio import tqdm_asyncio
21
+ except ImportError as e:
22
+
23
+ class tqdm_asyncio: # type: ignore [no-redef]
24
+ @staticmethod
25
+ def as_completed(*args, **kwargs):
26
+ raise ImportError("You must have tqdm installed to use this feature")
27
+
28
+ cdef object _tqdm_as_completed = tqdm_asyncio.as_completed
29
+ del tqdm_asyncio
30
+
31
+ # cdef iter
32
+ cdef object ASyncIterator = iter.ASyncIterator
33
+
34
+
35
+ @overload
36
+ def as_completed(
37
+ fs: Iterable[Awaitable[T]],
38
+ *,
39
+ timeout: Optional[float] = None,
40
+ return_exceptions: bool = False,
41
+ aiter: Literal[False] = False,
42
+ tqdm: bool = False,
43
+ **tqdm_kwargs: Any
44
+ ) -> Iterator[Coroutine[Any, Any, T]]: ...
45
+ @overload
46
+ def as_completed(
47
+ fs: Iterable[Awaitable[T]],
48
+ *,
49
+ timeout: Optional[float] = None,
50
+ return_exceptions: bool = False,
51
+ aiter: Literal[True] = True,
52
+ tqdm: bool = False,
53
+ **tqdm_kwargs: Any
54
+ ) -> ASyncIterator[T]: ...
55
+ @overload
56
+ def as_completed(
57
+ fs: Mapping[K, Awaitable[V]],
58
+ *,
59
+ timeout: Optional[float] = None,
60
+ return_exceptions: bool = False,
61
+ aiter: Literal[False] = False,
62
+ tqdm: bool = False,
63
+ **tqdm_kwargs: Any
64
+ ) -> Iterator[Coroutine[Any, Any, Tuple[K, V]]]: ...
65
+ @overload
66
+ def as_completed(
67
+ fs: Mapping[K, Awaitable[V]],
68
+ *,
69
+ timeout: Optional[float] = None,
70
+ return_exceptions: bool = False,
71
+ aiter: Literal[True] = True,
72
+ tqdm: bool = False,
73
+ **tqdm_kwargs: Any
74
+ ) -> ASyncIterator[Tuple[K, V]]: ...
75
+ def as_completed(
76
+ fs,
77
+ *,
78
+ timeout: Optional[float] = None,
79
+ return_exceptions: bool = False,
80
+ aiter: bool = False,
81
+ tqdm: bool = False,
82
+ **tqdm_kwargs: Any
83
+ ):
84
+ """
85
+ Concurrently awaits a list of awaitable objects or mappings of awaitables and returns an iterator of results.
86
+
87
+ This function extends Python's :func:`asyncio.as_completed`, providing additional features for mixed use cases of individual awaitable objects and mappings of awaitables.
88
+
89
+ Differences from :func:`asyncio.as_completed`:
90
+ - Uses type hints for use with static type checkers.
91
+ - Supports either individual awaitables or a k:v mapping of awaitables.
92
+ - Can be used as an async iterator which yields the result values using :class:`ASyncIterator`.
93
+ - Provides progress reporting using :mod:`tqdm` if 'tqdm' is set to True.
94
+
95
+ Note:
96
+ The `return_exceptions` parameter is used to wrap awaitables with exceptions if set to True, allowing exceptions to be returned as results instead of being raised.
97
+
98
+ Args:
99
+ fs: The awaitables to await concurrently. It can be a list of individual awaitables or a mapping of awaitables.
100
+ timeout: The maximum time, in seconds, to wait for the completion of awaitables. Defaults to None (no timeout).
101
+ return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
102
+ aiter: If True, returns an async iterator of results using :class:`ASyncIterator`. Defaults to False.
103
+ tqdm: If True, enables progress reporting using :mod:`tqdm`. Defaults to False.
104
+ **tqdm_kwargs: Additional keyword arguments for :mod:`tqdm` if progress reporting is enabled.
105
+
106
+ Examples:
107
+ Awaiting individual awaitables:
108
+
109
+ >>> awaitables = [async_function1(), async_function2()]
110
+ >>> for coro in as_completed(awaitables):
111
+ ... val = await coro
112
+ ... ...
113
+
114
+ >>> async for val in as_completed(awaitables, aiter=True):
115
+ ... ...
116
+
117
+ Awaiting mappings of awaitables:
118
+
119
+ >>> mapping = {'key1': async_function1(), 'key2': async_function2()}
120
+ >>> for coro in as_completed(mapping):
121
+ ... k, v = await coro
122
+ ... ...
123
+
124
+ >>> async for k, v in as_completed(mapping, aiter=True):
125
+ ... ...
126
+
127
+ See Also:
128
+ - :func:`asyncio.as_completed`
129
+ - :class:`ASyncIterator`
130
+ """
131
+ if isinstance(fs, Mapping):
132
+ return as_completed_mapping(
133
+ mapping=fs,
134
+ timeout=timeout or 0,
135
+ return_exceptions=return_exceptions,
136
+ aiter=aiter,
137
+ tqdm=tqdm,
138
+ tqdm_kwargs=tqdm_kwargs,
139
+ )
140
+ if return_exceptions:
141
+ fs = [_exc_wrap(f) for f in fs]
142
+ return (
143
+ ASyncIterator(
144
+ __yield_as_completed(fs, timeout=timeout, tqdm=tqdm, **tqdm_kwargs)
145
+ )
146
+ if aiter
147
+ else (
148
+ _tqdm_as_completed(fs, timeout=timeout, **tqdm_kwargs)
149
+ if tqdm
150
+ else _as_completed(fs, timeout=timeout)
151
+ )
152
+ )
153
+
154
+
155
+ cdef object as_completed_mapping(
156
+ object mapping,
157
+ unsigned int timeout,
158
+ bint return_exceptions,
159
+ bint aiter,
160
+ bint tqdm,
161
+ dict[str, object] tqdm_kwargs,
162
+ ):
163
+ """
164
+ Concurrently awaits a mapping of awaitable objects and returns an iterator or async iterator of results.
165
+
166
+ This function is designed to await a mapping of awaitable objects, where each key-value pair represents a unique awaitable. It enables concurrent execution and gathers results into an iterator or an async iterator.
167
+
168
+ Args:
169
+ mapping: A dictionary-like object where keys are of type K and values are awaitable objects of type V.
170
+ timeout: The maximum time, in seconds, to wait for the completion of awaitables. Defaults to None (no timeout).
171
+ return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
172
+ aiter: If True, returns an async iterator of results using :class:`ASyncIterator`. Defaults to False.
173
+ tqdm: If True, enables progress reporting using :mod:`tqdm`. Defaults to False.
174
+ **tqdm_kwargs: Additional keyword arguments for :mod:`tqdm` if progress reporting is enabled.
175
+
176
+ Example:
177
+ >>> mapping = {'key1': async_function1(), 'key2': async_function2()}
178
+ >>> for coro in as_completed_mapping(mapping):
179
+ ... k, v = await coro
180
+ ... ...
181
+
182
+ >>> async for k, v in as_completed_mapping(mapping, aiter=True):
183
+ ... ...
184
+
185
+ See Also:
186
+ - :func:`as_completed`
187
+ - :class:`ASyncIterator`
188
+ """
189
+ return as_completed(
190
+ [
191
+ __mapping_wrap(k, v, return_exceptions=return_exceptions)
192
+ for k, v in mapping.items()
193
+ ],
194
+ timeout=timeout or None,
195
+ aiter=aiter,
196
+ tqdm=tqdm,
197
+ **tqdm_kwargs
198
+ )
199
+
200
+
201
+ async def _exc_wrap(awaitable: Awaitable[T]) -> Union[T, Exception]:
202
+ """Wraps an awaitable to catch exceptions and return them instead of raising.
203
+
204
+ Args:
205
+ awaitable: The awaitable to wrap.
206
+
207
+ Returns:
208
+ The result of the awaitable or the exception if one is raised.
209
+ """
210
+ try:
211
+ return await awaitable
212
+ except Exception as e:
213
+ return e
214
+
215
+
216
+ async def __yield_as_completed(
217
+ futs: Iterable[Awaitable[T]],
218
+ *,
219
+ timeout: Optional[float] = None,
220
+ return_exceptions: bool = False,
221
+ tqdm: bool = False,
222
+ **tqdm_kwargs: Any
223
+ ) -> AsyncIterator[T]:
224
+ """Yields results from awaitables as they complete.
225
+
226
+ Args:
227
+ futs: The awaitables to await.
228
+ timeout: The maximum time, in seconds, to wait for the completion of awaitables. Defaults to None (no timeout).
229
+ return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
230
+ tqdm: If True, enables progress reporting using :mod:`tqdm`. Defaults to False.
231
+ **tqdm_kwargs: Additional keyword arguments for :mod:`tqdm` if progress reporting is enabled.
232
+ """
233
+ for fut in as_completed(
234
+ futs,
235
+ timeout=timeout,
236
+ return_exceptions=return_exceptions,
237
+ tqdm=tqdm,
238
+ **tqdm_kwargs
239
+ ):
240
+ yield await fut
241
+
242
+
243
+ @overload
244
+ async def __mapping_wrap(
245
+ k: K, v: Awaitable[V], return_exceptions: Literal[True] = True
246
+ ) -> Union[V, Exception]: ...
247
+ @overload
248
+ async def __mapping_wrap(
249
+ k: K, v: Awaitable[V], return_exceptions: Literal[False] = False
250
+ ) -> V: ...
251
+ async def __mapping_wrap(
252
+ k: K, v: Awaitable[V], return_exceptions: bool = False
253
+ ) -> Union[V, Exception]:
254
+ """Wraps a key-value pair of awaitable to catch exceptions and return them with the key.
255
+
256
+ Args:
257
+ k: The key associated with the awaitable.
258
+ v: The awaitable to wrap.
259
+ return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
260
+
261
+ Returns:
262
+ A tuple of the key and the result of the awaitable or the exception if one is raised.
263
+ """
264
+ try:
265
+ return k, await v
266
+ except Exception as e:
267
+ if return_exceptions:
268
+ return k, e
269
+ raise