Skip to content

Commit 6117a1a

Browse files
document strict parameter
1 parent e82e753 commit 6117a1a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

asyncstdlib/itertools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,20 @@ async def accumulate(iterable, function, *, initial):
122122
yield value
123123

124124

125-
async def batched(iterable: AnyIterable[T], n: int) -> AsyncIterator[Tuple[T, ...]]:
125+
async def batched(
126+
iterable: AnyIterable[T], n: int, strict: bool = False
127+
) -> AsyncIterator[Tuple[T, ...]]:
126128
"""
127129
Batch the ``iterable`` to tuples of the length ``n``.
128130
129131
This lazily exhausts ``iterable`` and returns each batch as soon as it's ready.
132+
If ``strict`` is :py:data:`True` then each batch is checked for correct size:
133+
:py:exc:`ValueError` is raised if the last batch is smaller than ``n``.
130134
"""
131135
if n < 1:
132136
raise ValueError("n must be at least one")
137+
if strict:
138+
raise NotImplemented("batched(..., strict=True)")
133139
async with ScopedIter(iterable) as item_iter:
134140
while batch := await atuple(islice(_borrow(item_iter), n)):
135141
yield batch

0 commit comments

Comments
 (0)