Skip to content

gh-154570: Fix itertools.accumulate() silently corrupting its total on reentrancy#154571

Open
PhysicistJohn wants to merge 1 commit into
python:mainfrom
PhysicistJohn:gh-154570-accumulate-reentrancy-fix
Open

gh-154570: Fix itertools.accumulate() silently corrupting its total on reentrancy#154571
PhysicistJohn wants to merge 1 commit into
python:mainfrom
PhysicistJohn:gh-154570-accumulate-reentrancy-fix

Conversation

@PhysicistJohn

Copy link
Copy Markdown

A source iterable or func= callable that calls back into next() on
the same accumulate object mid-step silently corrupted the running
total instead of erroring. Fixes gh-154570.

Adds a running guard field to accumulateobject, mirroring the
existing pattern already used by teedataobject for the identical
class of bug (see teedataobject_getitem_lock_held). accumulate
now raises RuntimeError("cannot re-enter the accumulate iterator")
on reentrant access instead of silently corrupting state, matching
tee's existing behavior for the same defect class.

Adds a regression test (test_accumulate_reenter) in the same style
as the existing test_tee_reenter.

…otal on reentrancy

A source iterable or func= callable that calls back into next() on
the same accumulate object mid-step silently corrupted the running
total instead of erroring.

Adds a running guard field to accumulateobject, mirroring the
existing pattern already used by teedataobject for the identical
class of bug (see teedataobject_getitem_lock_held). accumulate now
raises RuntimeError("cannot re-enter the accumulate iterator") on
reentrant access instead of silently corrupting state, matching
tee's existing behavior for the same defect class.

Adds a regression test (test_accumulate_reenter) in the same style
as the existing test_tee_reenter.
@python-cla-bot

python-cla-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

itertools.accumulate() silently corrupts its running total on reentrancy

1 participant