python-iterutils 0.1.6__py3-none-any.whl → 0.1.7__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 +38 -5
- {python_iterutils-0.1.6.dist-info → python_iterutils-0.1.7.dist-info}/METADATA +2 -1
- python_iterutils-0.1.7.dist-info/RECORD +7 -0
- python_iterutils-0.1.6.dist-info/RECORD +0 -7
- {python_iterutils-0.1.6.dist-info → python_iterutils-0.1.7.dist-info}/LICENSE +0 -0
- {python_iterutils-0.1.6.dist-info → python_iterutils-0.1.7.dist-info}/WHEEL +0 -0
iterutils/__init__.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 1,
|
|
5
|
+
__version__ = (0, 1, 7)
|
|
6
6
|
__all__ = [
|
|
7
7
|
"Return", "Yield", "YieldFrom", "iterable", "async_iterable", "foreach", "async_foreach",
|
|
8
8
|
"through", "async_through", "flatten", "async_flatten", "map", "filter", "reduce", "zip",
|
|
@@ -23,8 +23,10 @@ from contextlib import asynccontextmanager, contextmanager, ExitStack, AsyncExit
|
|
|
23
23
|
from dataclasses import dataclass
|
|
24
24
|
from itertools import batched, pairwise
|
|
25
25
|
from inspect import isawaitable, iscoroutinefunction
|
|
26
|
+
from sys import _getframe
|
|
26
27
|
from _thread import start_new_thread
|
|
27
28
|
from time import sleep, time
|
|
29
|
+
from types import FrameType
|
|
28
30
|
from typing import overload, Any, AsyncContextManager, ContextManager, Literal
|
|
29
31
|
|
|
30
32
|
from asynctools import (
|
|
@@ -452,13 +454,32 @@ def cut_iter(
|
|
|
452
454
|
yield stop, stop - start
|
|
453
455
|
|
|
454
456
|
|
|
457
|
+
def _get_async(back: int = 2) -> bool:
|
|
458
|
+
f: None | FrameType
|
|
459
|
+
f = _getframe(back)
|
|
460
|
+
f_globals = f.f_globals
|
|
461
|
+
f_locals = f.f_locals
|
|
462
|
+
if f_locals is f_globals:
|
|
463
|
+
return f_locals.get("async_") or False
|
|
464
|
+
while f_locals is not f_globals:
|
|
465
|
+
if "async_" in f_locals:
|
|
466
|
+
return f_locals["async_"] or False
|
|
467
|
+
f = f.f_back
|
|
468
|
+
if f is None:
|
|
469
|
+
break
|
|
470
|
+
f_locals = f.f_locals
|
|
471
|
+
return False
|
|
472
|
+
|
|
473
|
+
|
|
455
474
|
def run_gen_step[T](
|
|
456
475
|
gen_step: Generator[Any, Any, T] | Callable[[], Generator[Any, Any, T]],
|
|
457
476
|
*,
|
|
458
|
-
async_: bool =
|
|
477
|
+
async_: None | bool = None,
|
|
459
478
|
threaded: bool = False,
|
|
460
479
|
as_iter: bool = False,
|
|
461
480
|
) -> T:
|
|
481
|
+
if async_ is None:
|
|
482
|
+
async_ = _get_async()
|
|
462
483
|
if callable(gen_step):
|
|
463
484
|
gen = gen_step()
|
|
464
485
|
close = gen.close
|
|
@@ -561,7 +582,15 @@ def run_gen_step_iter(
|
|
|
561
582
|
gen_step: Generator | Callable[[], Generator],
|
|
562
583
|
threaded: bool = False,
|
|
563
584
|
*,
|
|
564
|
-
async_:
|
|
585
|
+
async_: None = None,
|
|
586
|
+
) -> Iterator | AsyncIterator:
|
|
587
|
+
...
|
|
588
|
+
@overload
|
|
589
|
+
def run_gen_step_iter(
|
|
590
|
+
gen_step: Generator | Callable[[], Generator],
|
|
591
|
+
threaded: bool = False,
|
|
592
|
+
*,
|
|
593
|
+
async_: Literal[False],
|
|
565
594
|
) -> Iterator:
|
|
566
595
|
...
|
|
567
596
|
@overload
|
|
@@ -576,8 +605,10 @@ def run_gen_step_iter(
|
|
|
576
605
|
gen_step: Generator | Callable[[], Generator],
|
|
577
606
|
threaded: bool = False,
|
|
578
607
|
*,
|
|
579
|
-
async_: bool =
|
|
608
|
+
async_: None | bool = None,
|
|
580
609
|
) -> Iterator | AsyncIterator:
|
|
610
|
+
if async_ is None:
|
|
611
|
+
async_ = _get_async()
|
|
581
612
|
if callable(gen_step):
|
|
582
613
|
gen = gen_step()
|
|
583
614
|
close = gen.close
|
|
@@ -687,9 +718,11 @@ def run_gen_step_iter(
|
|
|
687
718
|
def as_gen_step(
|
|
688
719
|
func: Callable,
|
|
689
720
|
/,
|
|
690
|
-
async_: bool =
|
|
721
|
+
async_: None | bool = None,
|
|
691
722
|
iter: bool = False,
|
|
692
723
|
) -> Callable:
|
|
724
|
+
if async_ is None:
|
|
725
|
+
async_ = _get_async()
|
|
693
726
|
def wrapper(*args, **kwds):
|
|
694
727
|
if iter:
|
|
695
728
|
return run_gen_step_iter(func(*args, **kwds), async_=async_) # type: ignore
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-iterutils
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
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
|
|
@@ -21,6 +21,7 @@ Classifier: Topic :: Software Development
|
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries
|
|
22
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
23
|
Requires-Dist: python-asynctools (>=0.0.10)
|
|
24
|
+
Requires-Dist: python-decotools (>=0.0.2)
|
|
24
25
|
Requires-Dist: python-texttools (>=0.0.3)
|
|
25
26
|
Requires-Dist: python-undefined (>=0.0.3)
|
|
26
27
|
Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-iterutils
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
iterutils/__init__.py,sha256=BR4ZaZouhl3o9e6ZrBLLEBRfNJzKik8Et-B38Lw_yf0,27444
|
|
3
|
+
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_iterutils-0.1.7.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_iterutils-0.1.7.dist-info/METADATA,sha256=DkEirEtm5-ycdVDBZwb_o-0poNqQDA8Gv5QfJ5o4SwA,1468
|
|
6
|
+
python_iterutils-0.1.7.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
+
python_iterutils-0.1.7.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
iterutils/__init__.py,sha256=q5UPgJ2fSDIMQIRFyKlgLqWDiy-b_G8Ft6BSFz_lH3Y,26588
|
|
3
|
-
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_iterutils-0.1.6.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_iterutils-0.1.6.dist-info/METADATA,sha256=XfsSpEENF-pQdLvFDu4TwX60uxwvfqYIWFpdYNqlqkU,1426
|
|
6
|
-
python_iterutils-0.1.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
-
python_iterutils-0.1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|