Skip to content

Commit 29df8e8

Browse files
sampsoncclaude
andcommitted
gh-145678: Simplify test_grouper_next_reentrant_eq_does_not_crash
Use a single variable `g` instead of `outer_grouper`/`g`, matching the style of the sibling test test_groupby_reentrant_eq_does_not_crash. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 79bcea0 commit 29df8e8

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

Lib/test/test_itertools.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,6 @@ def test_grouper_next_reentrant_eq_does_not_crash(self):
759759
# gbo->currkey / igo->tgtkey before calling PyObject_RichCompareBool,
760760
# so a reentrant __eq__ that advanced the parent groupby could free
761761
# those objects while they were still being compared (use-after-free).
762-
outer_grouper = None
763-
764762
class Key:
765763
def __init__(self, val, do_advance):
766764
self.val = val
@@ -769,10 +767,8 @@ def __init__(self, val, do_advance):
769767
def __eq__(self, other):
770768
if self.do_advance:
771769
self.do_advance = False
772-
# Advance the parent groupby iterator from inside __eq__,
773-
# which calls groupby_step() and frees the old currkey.
774770
try:
775-
next(outer_grouper)
771+
next(g)
776772
except StopIteration:
777773
pass
778774
return NotImplemented
@@ -781,10 +777,8 @@ def __eq__(self, other):
781777
def __hash__(self):
782778
return hash(self.val)
783779

784-
values = [1, 1, 2]
785780
keys_iter = iter([Key(1, True), Key(1, False), Key(2, False)])
786-
g = itertools.groupby(values, lambda _: next(keys_iter))
787-
outer_grouper = g
781+
g = itertools.groupby([1, 1, 2], lambda _: next(keys_iter))
788782
k, grp = next(g)
789783
list(grp) # must not crash with address sanitizer
790784

0 commit comments

Comments
 (0)