python-iterutils 0.2.5__py3-none-any.whl → 0.2.5.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 +34 -20
- {python_iterutils-0.2.5.dist-info → python_iterutils-0.2.5.2.dist-info}/METADATA +1 -1
- python_iterutils-0.2.5.2.dist-info/RECORD +7 -0
- python_iterutils-0.2.5.dist-info/RECORD +0 -7
- {python_iterutils-0.2.5.dist-info → python_iterutils-0.2.5.2.dist-info}/LICENSE +0 -0
- {python_iterutils-0.2.5.dist-info → python_iterutils-0.2.5.2.dist-info}/WHEEL +0 -0
iterutils/__init__.py
CHANGED
|
@@ -7,8 +7,9 @@ __all__ = [
|
|
|
7
7
|
"Yield", "YieldFrom", "iterable", "async_iterable",
|
|
8
8
|
"run_gen_step", "run_gen_step_iter", "as_gen_step",
|
|
9
9
|
"as_gen_step_iter", "split_cm, ""with_iter_next",
|
|
10
|
-
"map", "filter", "reduce", "zip", "chain",
|
|
11
|
-
"
|
|
10
|
+
"map", "filter", "reduce", "zip", "chain",
|
|
11
|
+
"chain_from_iterable", "chunked", "foreach",
|
|
12
|
+
"async_foreach", "through", "async_through",
|
|
12
13
|
"flatten", "async_flatten", "collect", "async_collect",
|
|
13
14
|
"group_collect", "async_group_collect", "iter_unique",
|
|
14
15
|
"async_iter_unique", "wrap_iter", "wrap_aiter", "acc_step",
|
|
@@ -74,24 +75,27 @@ def async_iterable(obj, /) -> bool:
|
|
|
74
75
|
return isinstance(obj, AsyncIterable)
|
|
75
76
|
|
|
76
77
|
|
|
77
|
-
def
|
|
78
|
+
def _coalesce(vals, default=None):
|
|
79
|
+
for val in vals:
|
|
80
|
+
if val is not None:
|
|
81
|
+
return val
|
|
82
|
+
return default
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@overload
|
|
86
|
+
def _get_async(back: int = 2, /, *, default: Literal[False] = False) -> bool:
|
|
87
|
+
...
|
|
88
|
+
@overload
|
|
89
|
+
def _get_async[T](back: int = 2, /, *, default: T) -> bool | T:
|
|
90
|
+
...
|
|
91
|
+
def _get_async[T](back: int = 2, /, *, default: Literal[False] | T = False) -> bool | T:
|
|
78
92
|
"""往上查找,从最近的调用栈的命名空间中获取 `async_` 的值
|
|
79
93
|
"""
|
|
80
|
-
f: None | FrameType
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return f_locals.get("async_") or False
|
|
86
|
-
while f_locals is not None and f_locals is not f_globals:
|
|
87
|
-
if "async_" in f_locals:
|
|
88
|
-
if f_locals["async_"] is not None:
|
|
89
|
-
return f_locals["async_"]
|
|
90
|
-
f = f.f_back
|
|
91
|
-
if f is None:
|
|
92
|
-
break
|
|
93
|
-
f_locals = f.f_locals
|
|
94
|
-
return False
|
|
94
|
+
def iter_frams(f: None | FrameType = _getframe(back)):
|
|
95
|
+
while f:
|
|
96
|
+
yield f.f_locals.get("async_")
|
|
97
|
+
f = f.f_back
|
|
98
|
+
return _coalesce(iter_frams(), default)
|
|
95
99
|
|
|
96
100
|
|
|
97
101
|
def _run_gen_step(gen: Generator, /):
|
|
@@ -270,10 +274,14 @@ def as_gen_step[**Args](
|
|
|
270
274
|
gen_step: Callable[Args, Generator],
|
|
271
275
|
/,
|
|
272
276
|
) -> Callable[Args, Any]:
|
|
277
|
+
default_async = _get_async(default=None)
|
|
273
278
|
def wrapper(*args: Args.args, **kwds: Args.kwargs):
|
|
274
279
|
return run_gen_step(
|
|
275
280
|
gen_step,
|
|
276
|
-
|
|
281
|
+
_coalesce((
|
|
282
|
+
kwds.pop("async_", None),
|
|
283
|
+
_get_async(default=default_async),
|
|
284
|
+
)),
|
|
277
285
|
*args,
|
|
278
286
|
**kwds,
|
|
279
287
|
)
|
|
@@ -284,10 +292,14 @@ def as_gen_step_iter[**Args](
|
|
|
284
292
|
gen_step: Callable[Args, Generator],
|
|
285
293
|
/,
|
|
286
294
|
) -> Callable[Args, Iterable | AsyncIterable]:
|
|
295
|
+
default_async = _get_async(default=None)
|
|
287
296
|
def wrapper(*args: Args.args, **kwds: Args.kwargs):
|
|
288
297
|
return run_gen_step_iter(
|
|
289
298
|
gen_step,
|
|
290
|
-
|
|
299
|
+
_coalesce((
|
|
300
|
+
kwds.pop("async_", None),
|
|
301
|
+
_get_async(default=default_async),
|
|
302
|
+
)),
|
|
291
303
|
*args,
|
|
292
304
|
**kwds,
|
|
293
305
|
)
|
|
@@ -533,6 +545,8 @@ def chain_from_iterable[T](
|
|
|
533
545
|
return async_chain.from_iterable(iterables, threaded=threaded)
|
|
534
546
|
return _chain.from_iterable(iterables) # type: ignore
|
|
535
547
|
|
|
548
|
+
setattr(chain, "from_iterable", chain_from_iterable)
|
|
549
|
+
|
|
536
550
|
|
|
537
551
|
@overload
|
|
538
552
|
def chunked[T](
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
iterutils/__init__.py,sha256=PCXCgTYvEOJ5GCXeZEILDFYfCk9O5elECgTLJXWYpxw,33637
|
|
3
|
+
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_iterutils-0.2.5.2.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_iterutils-0.2.5.2.dist-info/METADATA,sha256=JM7iFXIRu01IwlLEMQsJq6NZeW56MNPHH3kl8WseTas,1429
|
|
6
|
+
python_iterutils-0.2.5.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
+
python_iterutils-0.2.5.2.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
iterutils/__init__.py,sha256=GJWB55mT2qVPXmSKIR0qfVQXiH2_7wZwpQTLVSNmqwg,33272
|
|
3
|
-
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_iterutils-0.2.5.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_iterutils-0.2.5.dist-info/METADATA,sha256=boKzeiFl7sWgEEk0XU9MShqgHHzbUbqAn37UWikXmrE,1427
|
|
6
|
-
python_iterutils-0.2.5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
-
python_iterutils-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|