mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-30346: An iterator produced by the itertools.groupby() iterator (#1569)
now becames exhausted after advancing the groupby iterator.
This commit is contained in:
parent
4facdf523a
commit
c247caf33f
4 changed files with 34 additions and 3 deletions
|
@ -401,13 +401,14 @@ loops that truncate the stream.
|
|||
def __iter__(self):
|
||||
return self
|
||||
def __next__(self):
|
||||
self.id = object()
|
||||
while self.currkey == self.tgtkey:
|
||||
self.currvalue = next(self.it) # Exit on StopIteration
|
||||
self.currkey = self.keyfunc(self.currvalue)
|
||||
self.tgtkey = self.currkey
|
||||
return (self.currkey, self._grouper(self.tgtkey))
|
||||
def _grouper(self, tgtkey):
|
||||
while self.currkey == tgtkey:
|
||||
return (self.currkey, self._grouper(self.tgtkey, self.id))
|
||||
def _grouper(self, tgtkey, id):
|
||||
while self.id is id and self.currkey == tgtkey:
|
||||
yield self.currvalue
|
||||
try:
|
||||
self.currvalue = next(self.it)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue