File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -134,18 +134,18 @@ async def batched(
134134 if n < 1 :
135135 raise ValueError ("n must be at least one" )
136136 async with ScopedIter (iterable ) as item_iter :
137- while True :
138- batch : list [T ] = []
139- try :
137+ batch : list [T ] = []
138+ try :
139+ while True :
140+ batch .clear ()
140141 for _ in range (n ):
141142 batch .append (await anext (item_iter ))
142- except StopAsyncIteration :
143- if strict and batch and len (batch ) < n :
144- raise ValueError ("batched(): incomplete batch" ) from None
143+ yield tuple (batch )
144+ except StopAsyncIteration :
145145 if batch :
146+ if strict and len (batch ) < n :
147+ raise ValueError ("batched(): incomplete batch" ) from None
146148 yield tuple (batch )
147- else :
148- break
149149
150150
151151class chain (AsyncIterator [T ]):
You can’t perform that action at this time.
0 commit comments