Commit 643254e
committed
gh-154570: Fix itertools.accumulate() silently corrupting its total 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.1 parent 66e313f commit 643254e
3 files changed
Lines changed: 38 additions & 1 deletion
File tree
- Lib/test
- Misc/NEWS.d/next/Library
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
160 | 179 | | |
161 | 180 | | |
162 | 181 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3079 | 3079 | | |
3080 | 3080 | | |
3081 | 3081 | | |
| 3082 | + | |
3082 | 3083 | | |
3083 | 3084 | | |
3084 | 3085 | | |
| |||
3120 | 3121 | | |
3121 | 3122 | | |
3122 | 3123 | | |
| 3124 | + | |
3123 | 3125 | | |
3124 | 3126 | | |
3125 | 3127 | | |
| |||
3160 | 3162 | | |
3161 | 3163 | | |
3162 | 3164 | | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
3163 | 3171 | | |
3164 | | - | |
| 3172 | + | |
| 3173 | + | |
3165 | 3174 | | |
| 3175 | + | |
3166 | 3176 | | |
3167 | 3177 | | |
3168 | 3178 | | |
| 3179 | + | |
3169 | 3180 | | |
3170 | 3181 | | |
3171 | 3182 | | |
| |||
3174 | 3185 | | |
3175 | 3186 | | |
3176 | 3187 | | |
| 3188 | + | |
3177 | 3189 | | |
3178 | 3190 | | |
3179 | 3191 | | |
| |||
0 commit comments