Skip to content

Commit

Permalink
Override __iter__ for peekable (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
dycw authored Sep 12, 2024
1 parent e575bb5 commit d6db439
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ idna==3.8
# yarl
img2pdf==0.5.1
# via dycw-utilities (pyproject.toml)
importlib-metadata==8.4.0
importlib-metadata==8.5.0
# via keyring
importlib-resources==6.4.5
# via pypiserver
Expand Down Expand Up @@ -186,7 +186,7 @@ multidict==6.1.0
# via
# aiohttp
# yarl
narwhals==1.6.4
narwhals==1.7.0
# via altair
nest-asyncio==1.6.0
# via dycw-utilities (pyproject.toml)
Expand Down Expand Up @@ -266,7 +266,7 @@ polars-lts-cpu==1.6.0
# via dycw-utilities (pyproject.toml)
pqdm==0.2.0
# via dycw-utilities (pyproject.toml)
protobuf==5.28.0
protobuf==5.28.1
# via
# streamlit
# vegafusion
Expand Down
2 changes: 1 addition & 1 deletion requirements/altair.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lxml==5.3.0
# via pikepdf
markupsafe==2.1.5
# via jinja2
narwhals==1.6.4
narwhals==1.7.0
# via altair
packaging==24.1
# via
Expand Down
4 changes: 2 additions & 2 deletions requirements/streamlit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ markupsafe==2.1.5
# via jinja2
mdurl==0.1.2
# via markdown-it-py
narwhals==1.6.4
narwhals==1.7.0
# via altair
numpy==2.1.1
# via
Expand All @@ -63,7 +63,7 @@ pillow==10.4.0
# via streamlit
pluggy==1.5.0
# via pytest
protobuf==5.28.0
protobuf==5.28.1
# via streamlit
pyarrow==17.0.0
# via streamlit
Expand Down
8 changes: 8 additions & 0 deletions src/tests/test_more_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def test_dropwhile(self) -> None:
expected = [5, 6, 7, 8, 9]
assert result == expected

def test_iter(self) -> None:
it = peekable(range(10))
values: list[int] = []
for value in it:
assert isinstance(value, int)
values.append(value)
assert len(values) == 10

def test_next(self) -> None:
it = peekable(range(10))
value = next(it)
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import annotations

__version__ = "0.53.2"
__version__ = "0.53.3"
5 changes: 5 additions & 0 deletions src/utilities/more_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class peekable(_peekable, Generic[_T]): # noqa: N801
def __init__(self, iterable: Iterable[_T], /) -> None:
super().__init__(iterable)

@override
def __iter__(self) -> Iterator[_T]: # pyright: ignore[reportIncompatibleMethodOverride]
while bool(self):
yield next(self)

@override
def __next__(self) -> _T:
return super().__next__()
Expand Down

0 comments on commit d6db439

Please sign in to comment.