python-iterutils 0.2.2__py3-none-any.whl → 0.2.3__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 CHANGED
@@ -2,7 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
- __version__ = (0, 2, 2)
5
+ __version__ = (0, 2, 3)
6
6
  __all__ = [
7
7
  "Return", "Yield", "YieldFrom", "iterable", "async_iterable",
8
8
  "foreach", "async_foreach", "through", "async_through", "flatten",
@@ -11,8 +11,8 @@ __all__ = [
11
11
  "iter_unique", "async_iter_unique", "wrap_iter", "wrap_aiter",
12
12
  "acc_step", "cut_iter", "iter_gen_step", "iter_gen_step_async",
13
13
  "run_gen_step", "run_gen_step_sync_iter", "run_gen_step_async_iter",
14
- "run_gen_step_iter", "as_gen_step", "bfs_gen", "with_iter_next",
15
- "backgroud_loop",
14
+ "run_gen_step_iter", "as_gen_step", "as_gen_step_iter", "bfs_gen",
15
+ "with_iter_next", "backgroud_loop",
16
16
  ]
17
17
 
18
18
  from abc import ABC, abstractmethod
@@ -813,6 +813,18 @@ async def iter_gen_step_async(
813
813
  await close()
814
814
 
815
815
 
816
+ @overload
817
+ def run_gen_step(
818
+ gen_step: Generator | Callable[[], Generator],
819
+ may_await: bool | Literal[1] = True,
820
+ may_call: bool | Literal[1] = True,
821
+ threaded: bool = False,
822
+ running_flag: None | SupportsBool | Callable[[], SupportsBool] | Callable[[], Awaitable[SupportsBool]] = None,
823
+ *,
824
+ async_: None = None,
825
+ ):
826
+ ...
827
+ @overload
816
828
  def run_gen_step(
817
829
  gen_step: Generator | Callable[[], Generator],
818
830
  may_await: bool | Literal[1] = True,
@@ -820,7 +832,28 @@ def run_gen_step(
820
832
  threaded: bool = False,
821
833
  running_flag: None | SupportsBool | Callable[[], SupportsBool] | Callable[[], Awaitable[SupportsBool]] = None,
822
834
  *,
823
- async_: None | bool = None,
835
+ async_: Literal[False],
836
+ ):
837
+ ...
838
+ @overload
839
+ def run_gen_step(
840
+ gen_step: Generator | Callable[[], Generator],
841
+ may_await: bool | Literal[1] = True,
842
+ may_call: bool | Literal[1] = True,
843
+ threaded: bool = False,
844
+ running_flag: None | SupportsBool | Callable[[], SupportsBool] | Callable[[], Awaitable[SupportsBool]] = None,
845
+ *,
846
+ async_: Literal[True],
847
+ ) -> Coroutine:
848
+ ...
849
+ def run_gen_step(
850
+ gen_step: Generator | Callable[[], Generator],
851
+ may_await: bool | Literal[1] = True,
852
+ may_call: bool | Literal[1] = True,
853
+ threaded: bool = False,
854
+ running_flag: None | SupportsBool | Callable[[], SupportsBool] | Callable[[], Awaitable[SupportsBool]] = None,
855
+ *,
856
+ async_: None | Literal[False, True] = None,
824
857
  ):
825
858
  """
826
859
  """
@@ -1013,6 +1046,7 @@ def run_gen_step_iter(
1013
1046
  may_await: bool | Literal[1] = True,
1014
1047
  may_call: bool | Literal[1] = True,
1015
1048
  threaded: bool = False,
1049
+ running_flag: None | SupportsBool | Callable[[], SupportsBool] | Callable[[], Awaitable[SupportsBool]] = None,
1016
1050
  *,
1017
1051
  async_: None = None,
1018
1052
  ) -> Iterator | AsyncIterator:
@@ -1023,6 +1057,7 @@ def run_gen_step_iter(
1023
1057
  may_await: bool | Literal[1] = True,
1024
1058
  may_call: bool | Literal[1] = True,
1025
1059
  threaded: bool = False,
1060
+ running_flag: None | SupportsBool | Callable[[], SupportsBool] | Callable[[], Awaitable[SupportsBool]] = None,
1026
1061
  *,
1027
1062
  async_: Literal[False],
1028
1063
  ) -> Iterator:
@@ -1033,6 +1068,7 @@ def run_gen_step_iter(
1033
1068
  may_await: bool | Literal[1] = True,
1034
1069
  may_call: bool | Literal[1] = True,
1035
1070
  threaded: bool = False,
1071
+ running_flag: None | SupportsBool | Callable[[], SupportsBool] | Callable[[], Awaitable[SupportsBool]] = None,
1036
1072
  *,
1037
1073
  async_: Literal[True],
1038
1074
  ) -> AsyncIterator:
@@ -1042,8 +1078,9 @@ def run_gen_step_iter(
1042
1078
  may_await: bool | Literal[1] = True,
1043
1079
  may_call: bool | Literal[1] = True,
1044
1080
  threaded: bool = False,
1081
+ running_flag: None | SupportsBool | Callable[[], SupportsBool] | Callable[[], Awaitable[SupportsBool]] = None,
1045
1082
  *,
1046
- async_: None | bool = None,
1083
+ async_: None | Literal[False, True] = None,
1047
1084
  ) -> Iterator | AsyncIterator:
1048
1085
  """
1049
1086
  """
@@ -1062,38 +1099,41 @@ def run_gen_step_iter(
1062
1099
 
1063
1100
  @optional
1064
1101
  def as_gen_step(
1065
- func: Callable,
1102
+ func: Callable[..., Generator],
1066
1103
  /,
1104
+ *deco_args,
1067
1105
  iter: bool = False,
1068
- may_await: bool | Literal[1] = True,
1069
- may_call: bool | Literal[1] = True,
1070
- threaded: bool = False,
1071
- running_flag: None | SupportsBool | Callable[[], SupportsBool] | Callable[[], Awaitable[SupportsBool]] = None,
1072
- *,
1073
- async_: None | bool = None,
1106
+ **deco_kwds,
1074
1107
  ) -> Callable:
1075
- """装饰器,构建一个 gen_step 函数
1076
- """
1077
- if async_ is None:
1078
- async_ = _get_async()
1079
- def wrapper(*args, **kwds):
1080
- if iter:
1081
- return run_gen_step_iter(
1082
- func(*args, **kwds),
1083
- may_await=may_await,
1084
- may_call=may_call,
1085
- threaded=threaded,
1086
- async_=async_, # type: ignore
1087
- )
1088
- else:
1089
- return run_gen_step(
1090
- func(*args, **kwds),
1091
- may_await=may_await,
1092
- may_call=may_call,
1093
- threaded=threaded,
1094
- running_flag=running_flag,
1095
- async_=async_,
1096
- )
1108
+ """装饰器,把生成器封装成 gen_step 函数
1109
+ """
1110
+ call = run_gen_step_iter if iter else run_gen_step
1111
+ def wrapper(*args, async_: Literal[False, True] = False, **kwds):
1112
+ return call(
1113
+ func(*args, async_=async_, **kwds),
1114
+ *deco_args,
1115
+ async_=async_,
1116
+ **deco_kwds,
1117
+ )
1118
+ return wrapper
1119
+
1120
+
1121
+ @optional
1122
+ def as_gen_step_iter(
1123
+ func: Callable[..., Generator],
1124
+ /,
1125
+ *deco_args,
1126
+ **deco_kwds,
1127
+ ) -> Callable:
1128
+ """装饰器,把生成器封装成 gen_step 函数
1129
+ """
1130
+ def wrapper(*args, async_: Literal[False, True] = False, **kwds):
1131
+ return run_gen_step_iter(
1132
+ func(*args, async_=async_, **kwds),
1133
+ *deco_args,
1134
+ async_=async_,
1135
+ **deco_kwds,
1136
+ )
1097
1137
  return wrapper
1098
1138
 
1099
1139
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-iterutils
3
- Version: 0.2.2
3
+ Version: 0.2.3
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
@@ -0,0 +1,7 @@
1
+ LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
+ iterutils/__init__.py,sha256=egZxWU804STaONEuyAjvI2R-nUbTXx1wU4AECgYu0jg,39456
3
+ iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ python_iterutils-0.2.3.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
5
+ python_iterutils-0.2.3.dist-info/METADATA,sha256=ZdhvscMtLIfrgiGyeXC30ZTSXg2v0J98cLu9YpVt7uo,1467
6
+ python_iterutils-0.2.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
+ python_iterutils-0.2.3.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
- iterutils/__init__.py,sha256=yCkEoGSY0n4E-_BvLRuoi50j4Kwuu-banqxIf-QloX4,37966
3
- iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- python_iterutils-0.2.2.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
5
- python_iterutils-0.2.2.dist-info/METADATA,sha256=xWgHLL5Q8knQfbWJkn9nijnp14koK8cvm8lw-JGGGrE,1467
6
- python_iterutils-0.2.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
- python_iterutils-0.2.2.dist-info/RECORD,,