python-iterutils 0.0.4.1__tar.gz → 0.0.4.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-iterutils
3
- Version: 0.0.4.1
3
+ Version: 0.0.4.2
4
4
  Summary: Python another itertools.
5
5
  Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-iterutils
6
6
  License: MIT
@@ -9,9 +9,11 @@ __all__ = [
9
9
  ]
10
10
 
11
11
  from asyncio import to_thread
12
- from collections.abc import AsyncIterable, AsyncIterator, Callable, Generator, Iterable, Iterator
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_: bool = False,
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
@@ -202,7 +223,18 @@ def run_gen_step(
202
223
  else:
203
224
  func = send(ret)
204
225
  except StopIteration as e:
205
- return e.value
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
206
238
  finally:
207
239
  if close is not None:
208
240
  if threaded:
@@ -221,7 +253,10 @@ def run_gen_step(
221
253
  else:
222
254
  func = send(ret)
223
255
  except StopIteration as e:
224
- return e.value
256
+ result = e.value
257
+ if as_iter:
258
+ result = iter(result)
259
+ return result
225
260
  finally:
226
261
  if close is not None:
227
262
  close()
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-iterutils"
3
- version = "0.0.4.1"
3
+ version = "0.0.4.2"
4
4
  description = "Python another itertools."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"