This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author arigo
Recipients arigo
Date 2015-11-24.08:07:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
itertools.accumulate() has got methods __reduce__() and __setstate__() which fail at saving/restoring the state in all cases.  Example:

   >>> a = itertools.accumulate([0.0, 42])
   >>> next(a)
   >>> b = copy.deepcopy(a)
   >>> next(a)
   >>> next(b)
   42           # should have been the same as the previous result

More precisely, the problem occurs when the C-level "total" field has some value whose truth-value is false.  Then __reduce__/__setstate__ will not restore the value of this field, but keep it NULL.  That's why in the example above the intermediate total of 0.0 is forgotten, and the next(b) call will again just pick the next value without doing any addition.  (The problem can hurt more than in this example if we use a custom function instead of addition.)

A fix is easy but, as far as I can tell, it requires breaking the pickled format of accumulate() iterators that have already started.
Date User Action Args
2015-11-24 08:07:23arigosetrecipients: + arigo
2015-11-24 08:07:23arigosetmessageid: <>
2015-11-24 08:07:23arigolinkissue25718 messages
2015-11-24 08:07:23arigocreate