python-iterutils 0.2.5.1__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 +29 -18
- {python_iterutils-0.2.5.1.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.1.dist-info/RECORD +0 -7
- {python_iterutils-0.2.5.1.dist-info → python_iterutils-0.2.5.2.dist-info}/LICENSE +0 -0
- {python_iterutils-0.2.5.1.dist-info → python_iterutils-0.2.5.2.dist-info}/WHEEL +0 -0
iterutils/__init__.py
CHANGED
|
@@ -75,24 +75,27 @@ def async_iterable(obj, /) -> bool:
|
|
|
75
75
|
return isinstance(obj, AsyncIterable)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
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:
|
|
79
92
|
"""往上查找,从最近的调用栈的命名空间中获取 `async_` 的值
|
|
80
93
|
"""
|
|
81
|
-
f: None | FrameType
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return f_locals.get("async_") or False
|
|
87
|
-
while f_locals is not None and f_locals is not f_globals:
|
|
88
|
-
if "async_" in f_locals:
|
|
89
|
-
if f_locals["async_"] is not None:
|
|
90
|
-
return f_locals["async_"]
|
|
91
|
-
f = f.f_back
|
|
92
|
-
if f is None:
|
|
93
|
-
break
|
|
94
|
-
f_locals = f.f_locals
|
|
95
|
-
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)
|
|
96
99
|
|
|
97
100
|
|
|
98
101
|
def _run_gen_step(gen: Generator, /):
|
|
@@ -271,10 +274,14 @@ def as_gen_step[**Args](
|
|
|
271
274
|
gen_step: Callable[Args, Generator],
|
|
272
275
|
/,
|
|
273
276
|
) -> Callable[Args, Any]:
|
|
277
|
+
default_async = _get_async(default=None)
|
|
274
278
|
def wrapper(*args: Args.args, **kwds: Args.kwargs):
|
|
275
279
|
return run_gen_step(
|
|
276
280
|
gen_step,
|
|
277
|
-
|
|
281
|
+
_coalesce((
|
|
282
|
+
kwds.pop("async_", None),
|
|
283
|
+
_get_async(default=default_async),
|
|
284
|
+
)),
|
|
278
285
|
*args,
|
|
279
286
|
**kwds,
|
|
280
287
|
)
|
|
@@ -285,10 +292,14 @@ def as_gen_step_iter[**Args](
|
|
|
285
292
|
gen_step: Callable[Args, Generator],
|
|
286
293
|
/,
|
|
287
294
|
) -> Callable[Args, Iterable | AsyncIterable]:
|
|
295
|
+
default_async = _get_async(default=None)
|
|
288
296
|
def wrapper(*args: Args.args, **kwds: Args.kwargs):
|
|
289
297
|
return run_gen_step_iter(
|
|
290
298
|
gen_step,
|
|
291
|
-
|
|
299
|
+
_coalesce((
|
|
300
|
+
kwds.pop("async_", None),
|
|
301
|
+
_get_async(default=default_async),
|
|
302
|
+
)),
|
|
292
303
|
*args,
|
|
293
304
|
**kwds,
|
|
294
305
|
)
|
|
@@ -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=aoUmnRzgOHOAT4hzUXPJ9A3bvUepx0ueCtjWl4XPT3k,33354
|
|
3
|
-
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_iterutils-0.2.5.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_iterutils-0.2.5.1.dist-info/METADATA,sha256=lp7fYBJQJTjPu5_nd262n54aUP_4k0-ngr_So_iSpbs,1429
|
|
6
|
-
python_iterutils-0.2.5.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
-
python_iterutils-0.2.5.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|