python-iterutils 0.0.7__tar.gz → 0.0.7.1__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.7
3
+ Version: 0.0.7.1
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
@@ -9,13 +9,14 @@ __all__ = [
9
9
  "Yield", "YieldFrom",
10
10
  ]
11
11
 
12
+ from dataclasses import dataclass
12
13
  from abc import ABC, abstractmethod
13
14
  from asyncio import to_thread
14
15
  from collections.abc import (
15
- AsyncIterable, AsyncIterator, Awaitable, Callable, Generator, Iterable, Iterator,
16
+ AsyncIterable, AsyncIterator, Callable, Generator, Iterable, Iterator,
16
17
  )
17
18
  from inspect import isawaitable
18
- from typing import overload, Any, Literal, NamedTuple, TypeVar
19
+ from typing import overload, Any, Literal, TypeVar
19
20
 
20
21
  from asynctools import async_zip, ensure_async, ensure_aiter
21
22
 
@@ -23,23 +24,23 @@ from asynctools import async_zip, ensure_async, ensure_aiter
23
24
  T = TypeVar("T")
24
25
 
25
26
 
26
- class YieldBase(ABC, Iterable):
27
- __slots__ = "value", "identity", "try_call_me"
27
+ @dataclass(slots=True, frozen=True)
28
+ class YieldBase(ABC):
29
+ value: Any
30
+ identity: bool = False
31
+ try_call_me: bool = True
32
+
28
33
  @property
29
34
  @abstractmethod
30
35
  def yield_type(self, /) -> int:
31
36
  ...
32
37
 
33
38
 
34
- @YieldBase.register
35
- class Yield(NamedTuple):
36
- value: Any
37
- identity: bool = False
38
- try_call_me: bool = True
39
- yield_type = 1 # type: ignore
39
+ class Yield(YieldBase):
40
+ yield_type = 1
40
41
 
41
42
 
42
- class YieldFrom(Yield):
43
+ class YieldFrom(YieldBase):
43
44
  yield_type = 2
44
45
 
45
46
 
@@ -309,8 +310,10 @@ def run_gen_step_iter(
309
310
  identity = False
310
311
  try_call_me = True
311
312
  if isinstance(ret, YieldBase):
313
+ identity = ret.identity
314
+ try_call_me = ret.try_call_me
312
315
  yield_type = ret.yield_type
313
- ret, identity, try_call_me = ret
316
+ ret = ret.value
314
317
  if not identity:
315
318
  if try_call_me and callable(ret):
316
319
  ret = ret()
@@ -364,8 +367,10 @@ def run_gen_step_iter(
364
367
  identity = False
365
368
  try_call_me = True
366
369
  if isinstance(ret, YieldBase):
370
+ identity = ret.identity
371
+ try_call_me = ret.try_call_me
367
372
  yield_type = ret.yield_type
368
- ret, identity, try_call_me = ret
373
+ ret = ret.value
369
374
  if not identity and try_call_me and callable(ret):
370
375
  ret = ret()
371
376
  return yield_type, ret
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-iterutils"
3
- version = "0.0.7"
3
+ version = "0.0.7.1"
4
4
  description = "Python another itertools."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"