[3.6] bpo-30347: Stop crashes when concurrently iterate over itertools.groupby() iterators. (GH-1557) (#3770)

(cherry picked from commit c740e4fe8a)
This commit is contained in:
Miss Islington (bot) 2017-09-26 12:20:22 -07:00 committed by Serhiy Storchaka
parent d6a356209a
commit 69b2dc8637
3 changed files with 56 additions and 36 deletions

View file

@ -1984,6 +1984,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...