mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +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
|
@ -751,6 +751,26 @@ class TestBasicOps(unittest.TestCase):
|
|||
self.assertEqual(set(keys), expectedkeys)
|
||||
self.assertEqual(len(keys), len(expectedkeys))
|
||||
|
||||
# Check case where inner iterator is used after advancing the groupby
|
||||
# iterator
|
||||
s = list(zip('AABBBAAAA', range(9)))
|
||||
it = groupby(s, testR)
|
||||
_, g1 = next(it)
|
||||
_, g2 = next(it)
|
||||
_, g3 = next(it)
|
||||
self.assertEqual(list(g1), [])
|
||||
self.assertEqual(list(g2), [])
|
||||
self.assertEqual(next(g3), ('A', 5))
|
||||
list(it) # exhaust the groupby iterator
|
||||
self.assertEqual(list(g3), [])
|
||||
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
it = groupby(s, testR)
|
||||
_, g = next(it)
|
||||
next(it)
|
||||
next(it)
|
||||
self.assertEqual(list(pickle.loads(pickle.dumps(g, proto))), [])
|
||||
|
||||
# Exercise pipes and filters style
|
||||
s = 'abracadabra'
|
||||
# sort s | uniq
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue