python-iterutils 0.0.4__py3-none-any.whl → 0.0.4.2__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 +60 -12
- {python_iterutils-0.0.4.dist-info → python_iterutils-0.0.4.2.dist-info}/METADATA +1 -1
- python_iterutils-0.0.4.2.dist-info/RECORD +7 -0
- iterutils/.DS_Store +0 -0
- python_iterutils-0.0.4.dist-info/RECORD +0 -8
- {python_iterutils-0.0.4.dist-info → python_iterutils-0.0.4.2.dist-info}/LICENSE +0 -0
- {python_iterutils-0.0.4.dist-info → python_iterutils-0.0.4.2.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
|
|
@@ -178,6 +199,7 @@ def run_gen_step(
|
|
|
178
199
|
gen = gen_step
|
|
179
200
|
close = None
|
|
180
201
|
send = gen.send
|
|
202
|
+
throw = gen.throw
|
|
181
203
|
if async_:
|
|
182
204
|
async def process():
|
|
183
205
|
try:
|
|
@@ -186,15 +208,33 @@ def run_gen_step(
|
|
|
186
208
|
else:
|
|
187
209
|
func = send(None)
|
|
188
210
|
while True:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
211
|
+
try:
|
|
212
|
+
ret = func()
|
|
213
|
+
if isawaitable(ret):
|
|
214
|
+
ret = await ret
|
|
215
|
+
except BaseException as e:
|
|
216
|
+
if threaded:
|
|
217
|
+
func = await to_thread(throw, e)
|
|
218
|
+
else:
|
|
219
|
+
func = throw(e)
|
|
194
220
|
else:
|
|
195
|
-
|
|
221
|
+
if threaded:
|
|
222
|
+
func = await to_thread(send, ret)
|
|
223
|
+
else:
|
|
224
|
+
func = send(ret)
|
|
196
225
|
except StopIteration as e:
|
|
197
|
-
|
|
226
|
+
result = e.value
|
|
227
|
+
if as_iter:
|
|
228
|
+
if isawaitable(result):
|
|
229
|
+
result = await result
|
|
230
|
+
try:
|
|
231
|
+
result = aiter(result)
|
|
232
|
+
except TypeError:
|
|
233
|
+
async def wrap(it):
|
|
234
|
+
for val in iter(it):
|
|
235
|
+
yield val
|
|
236
|
+
result = wrap(result)
|
|
237
|
+
return result
|
|
198
238
|
finally:
|
|
199
239
|
if close is not None:
|
|
200
240
|
if threaded:
|
|
@@ -206,9 +246,17 @@ def run_gen_step(
|
|
|
206
246
|
try:
|
|
207
247
|
func = send(None)
|
|
208
248
|
while True:
|
|
209
|
-
|
|
249
|
+
try:
|
|
250
|
+
ret = func()
|
|
251
|
+
except BaseException as e:
|
|
252
|
+
func = throw(e)
|
|
253
|
+
else:
|
|
254
|
+
func = send(ret)
|
|
210
255
|
except StopIteration as e:
|
|
211
|
-
|
|
256
|
+
result = e.value
|
|
257
|
+
if as_iter:
|
|
258
|
+
result = iter(result)
|
|
259
|
+
return result
|
|
212
260
|
finally:
|
|
213
261
|
if close is not None:
|
|
214
262
|
close()
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
iterutils/__init__.py,sha256=gB8PhcSVF_WfAHRPfHvjTLbO9-A843pA1vdahfKBRpw,7593
|
|
3
|
+
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_iterutils-0.0.4.2.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_iterutils-0.0.4.2.dist-info/METADATA,sha256=54xnC2-fhIS14RNphRtI_c_xnLUuT0CDPmjgUPZnZ30,1384
|
|
6
|
+
python_iterutils-0.0.4.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_iterutils-0.0.4.2.dist-info/RECORD,,
|
iterutils/.DS_Store
DELETED
|
Binary file
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
iterutils/.DS_Store,sha256=Kj3OcVIE2j02GFjUj8pr1YvdK4YSjlslELr_iRcRv68,6148
|
|
3
|
-
iterutils/__init__.py,sha256=M1KlG0BMF4oZIP4QU18m5riMnWO0oJKNP_SqVDlWKJo,6033
|
|
4
|
-
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
python_iterutils-0.0.4.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
6
|
-
python_iterutils-0.0.4.dist-info/METADATA,sha256=3CGonLEb1lXVVrsrd-08p1vMexFfRTdE6MxeCneF4vU,1382
|
|
7
|
-
python_iterutils-0.0.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
8
|
-
python_iterutils-0.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|