Skip to content

Commit 4be9d4f

Browse files
Update Lib/test/test_itertools.py
Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent e29c818 commit 4be9d4f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Lib/test/test_itertools.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,17 +734,25 @@ def keyfunc(obj):
734734
self.assertRaises(ExpectedError, gulp, [None, None], keyfunc)
735735

736736
def test_groupby_reentrant_eq_does_not_crash(self):
737-
class Key(bytearray):
738-
seen = False
737+
# regression test for gh-143543
738+
class Key:
739+
def __init__(self, do_advance):
740+
self.do_advance = do_advance
741+
739742
def __eq__(self, other):
740-
if not Key.seen:
741-
Key.seen = True
743+
if self.do_advance:
744+
self.do_advance = False
742745
next(g)
746+
return NotImplemented
743747
return False
744748

745-
g = itertools.groupby([Key(b"a"), Key(b"b")])
749+
def keys():
750+
yield Key(True)
751+
yield Key(False)
752+
753+
g = itertools.groupby([None, None], keys().send)
746754
next(g)
747-
next(g) # must not segfault
755+
next(g) # must pass with address sanitizer
748756

749757
def test_filter(self):
750758
self.assertEqual(list(filter(isEven, range(6))), [0,2,4])

0 commit comments

Comments
 (0)