python-iterutils 0.0.4.1__py3-none-any.whl → 0.0.4.3__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.
- iterutils/__init__.py +44 -5
- {python_iterutils-0.0.4.1.dist-info → python_iterutils-0.0.4.3.dist-info}/METADATA +1 -1
- python_iterutils-0.0.4.3.dist-info/RECORD +7 -0
- python_iterutils-0.0.4.1.dist-info/RECORD +0 -7
- {python_iterutils-0.0.4.1.dist-info → python_iterutils-0.0.4.3.dist-info}/LICENSE +0 -0
- {python_iterutils-0.0.4.1.dist-info → python_iterutils-0.0.4.3.dist-info}/WHEEL +0 -0
iterutils/__init__.py
CHANGED
|
@@ -9,9 +9,11 @@ __all__ = [
|
|
|
9
9
|
]
|
|
10
10
|
|
|
11
11
|
from asyncio import to_thread
|
|
12
|
-
from collections.abc import
|
|
12
|
+
from collections.abc import (
|
|
13
|
+
AsyncIterable, AsyncIterator, Awaitable, Callable, Generator, Iterable, Iterator,
|
|
14
|
+
)
|
|
13
15
|
from inspect import isawaitable
|
|
14
|
-
from typing import Any, TypeVar
|
|
16
|
+
from typing import overload, Any, Literal, TypeVar
|
|
15
17
|
|
|
16
18
|
from asynctools import async_zip, ensure_async, ensure_aiter
|
|
17
19
|
|
|
@@ -165,12 +167,31 @@ def cut_iter(
|
|
|
165
167
|
yield stop, stop - start
|
|
166
168
|
|
|
167
169
|
|
|
170
|
+
@overload
|
|
168
171
|
def run_gen_step(
|
|
169
172
|
gen_step: Generator[Callable, Any, T] | Callable[[], Generator[Callable, Any, T]],
|
|
170
173
|
*,
|
|
171
|
-
async_:
|
|
174
|
+
async_: Literal[False] = False,
|
|
172
175
|
threaded: bool = False,
|
|
176
|
+
as_iter: bool = False,
|
|
173
177
|
) -> T:
|
|
178
|
+
...
|
|
179
|
+
@overload
|
|
180
|
+
def run_gen_step(
|
|
181
|
+
gen_step: Generator[Callable, Any, T] | Callable[[], Generator[Callable, Any, T]],
|
|
182
|
+
*,
|
|
183
|
+
async_: Literal[True],
|
|
184
|
+
threaded: bool = False,
|
|
185
|
+
as_iter: bool = False,
|
|
186
|
+
) -> Awaitable[T]:
|
|
187
|
+
...
|
|
188
|
+
def run_gen_step(
|
|
189
|
+
gen_step: Generator[Callable, Any, T] | Callable[[], Generator[Callable, Any, T]],
|
|
190
|
+
*,
|
|
191
|
+
async_: bool = False,
|
|
192
|
+
threaded: bool = False,
|
|
193
|
+
as_iter: bool = False,
|
|
194
|
+
) -> T | Awaitable[T]:
|
|
174
195
|
if callable(gen_step):
|
|
175
196
|
gen = gen_step()
|
|
176
197
|
close = gen.close
|
|
@@ -209,7 +230,22 @@ def run_gen_step(
|
|
|
209
230
|
await to_thread(close)
|
|
210
231
|
else:
|
|
211
232
|
close()
|
|
212
|
-
|
|
233
|
+
result = process()
|
|
234
|
+
if as_iter:
|
|
235
|
+
async def wrap(result):
|
|
236
|
+
it = await result
|
|
237
|
+
try:
|
|
238
|
+
it = aiter(it)
|
|
239
|
+
except TypeError:
|
|
240
|
+
for val in iter(it):
|
|
241
|
+
if isawaitable(val):
|
|
242
|
+
val = await val
|
|
243
|
+
yield val
|
|
244
|
+
else:
|
|
245
|
+
async for val in it:
|
|
246
|
+
yield val
|
|
247
|
+
result = wrap(result)
|
|
248
|
+
return result
|
|
213
249
|
else:
|
|
214
250
|
try:
|
|
215
251
|
func = send(None)
|
|
@@ -221,7 +257,10 @@ def run_gen_step(
|
|
|
221
257
|
else:
|
|
222
258
|
func = send(ret)
|
|
223
259
|
except StopIteration as e:
|
|
224
|
-
|
|
260
|
+
result = e.value
|
|
261
|
+
if as_iter:
|
|
262
|
+
result = iter(result)
|
|
263
|
+
return result
|
|
225
264
|
finally:
|
|
226
265
|
if close is not None:
|
|
227
266
|
close()
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
iterutils/__init__.py,sha256=28I7UIPitCAj72fQsdq__WDN6F2-jsMrJGC-BShgWTQ,7651
|
|
3
|
+
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_iterutils-0.0.4.3.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_iterutils-0.0.4.3.dist-info/METADATA,sha256=lfVGyCq0C0HyQf2wkjznLunZmm3vJedXu69VSTOH_bE,1384
|
|
6
|
+
python_iterutils-0.0.4.3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_iterutils-0.0.4.3.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
iterutils/__init__.py,sha256=8a-fOfmc8G2JVE5Ua1EMYQk0FxNCvg4mUuocmEOupqE,6509
|
|
3
|
-
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_iterutils-0.0.4.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_iterutils-0.0.4.1.dist-info/METADATA,sha256=9x_AwMd02HKHBnJSZ0oP9M3oCVw-0QOWhJO42RQILcg,1384
|
|
6
|
-
python_iterutils-0.0.4.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
-
python_iterutils-0.0.4.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|