python-iterutils 0.0.4.2__tar.gz → 0.0.4.4__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.2
3
+ Version: 0.0.4.4
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
@@ -13,7 +13,7 @@ from collections.abc import (
13
13
  AsyncIterable, AsyncIterator, Awaitable, Callable, Generator, Iterable, Iterator,
14
14
  )
15
15
  from inspect import isawaitable
16
- from typing import overload, Any, Literal, TypeVar
16
+ from typing import Any, TypeVar
17
17
 
18
18
  from asynctools import async_zip, ensure_async, ensure_aiter
19
19
 
@@ -167,31 +167,13 @@ def cut_iter(
167
167
  yield stop, stop - start
168
168
 
169
169
 
170
- @overload
171
- def run_gen_step(
172
- gen_step: Generator[Callable, Any, T] | Callable[[], Generator[Callable, Any, T]],
173
- *,
174
- async_: Literal[False] = False,
175
- threaded: bool = False,
176
- as_iter: bool = False,
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
170
  def run_gen_step(
189
171
  gen_step: Generator[Callable, Any, T] | Callable[[], Generator[Callable, Any, T]],
190
172
  *,
191
173
  async_: bool = False,
192
174
  threaded: bool = False,
193
175
  as_iter: bool = False,
194
- ) -> T | Awaitable[T]:
176
+ ) -> T:
195
177
  if callable(gen_step):
196
178
  gen = gen_step()
197
179
  close = gen.close
@@ -223,25 +205,29 @@ def run_gen_step(
223
205
  else:
224
206
  func = send(ret)
225
207
  except StopIteration as e:
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
208
+ return e.value
238
209
  finally:
239
210
  if close is not None:
240
211
  if threaded:
241
212
  await to_thread(close)
242
213
  else:
243
214
  close()
244
- return process()
215
+ result = process()
216
+ if as_iter:
217
+ async def wrap(result):
218
+ it = await result
219
+ try:
220
+ it = aiter(it)
221
+ except TypeError:
222
+ for val in iter(it):
223
+ if isawaitable(val):
224
+ val = await val
225
+ yield val
226
+ else:
227
+ async for val in it:
228
+ yield val
229
+ result = wrap(result)
230
+ return result
245
231
  else:
246
232
  try:
247
233
  func = send(None)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-iterutils"
3
- version = "0.0.4.2"
3
+ version = "0.0.4.4"
4
4
  description = "Python another itertools."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"