Skip to content

Commit

Permalink
merge all exit conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfischer2781 committed Oct 15, 2024
1 parent 4e99042 commit f1d4f3a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions asyncstdlib/itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ async def batched(
if n < 1:
raise ValueError("n must be at least one")
async with ScopedIter(iterable) as item_iter:
while True:
batch: list[T] = []
try:
batch: list[T] = []
try:
while True:
batch.clear()
for _ in range(n):
batch.append(await anext(item_iter))
except StopAsyncIteration:
if strict and batch and len(batch) < n:
raise ValueError("batched(): incomplete batch") from None
yield tuple(batch)
except StopAsyncIteration:
if batch:
if strict and len(batch) < n:
raise ValueError("batched(): incomplete batch") from None
yield tuple(batch)
else:
break


class chain(AsyncIterator[T]):
Expand Down

0 comments on commit f1d4f3a

Please sign in to comment.