bpo-30347: Stop crashes when concurrently iterate over itertools.groupby() iterators. (#1557)

This commit is contained in:
Serhiy Storchaka 2017-09-26 21:47:56 +03:00 committed by GitHub
parent 114454e9f6
commit c740e4fe8a
3 changed files with 56 additions and 36 deletions

View file

@ -2017,6 +2017,30 @@ class RegressionTests(unittest.TestCase):
with self.assertRaises(StopIteration):
next(it)
def test_issue30347_1(self):
def f(n):
if n == 5:
list(b)
return n != 6
for (k, b) in groupby(range(10), f):
list(b) # shouldn't crash
def test_issue30347_2(self):
class K:
def __init__(self, v):
pass
def __eq__(self, other):
nonlocal i
i += 1
if i == 1:
next(g, None)
return True
i = 0
g = next(groupby(range(10), K))[1]
for j in range(2):
next(g, None) # shouldn't crash
class SubclassWithKwargsTest(unittest.TestCase):
def test_keywords_in_subclass(self):
# count is not subclassable...