Message255252
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)
0.0
>>> b = copy.deepcopy(a)
>>> next(a)
42.0
>>> 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:23 | arigo | set | recipients:
+ arigo |
2015-11-24 08:07:23 | arigo | set | messageid: <1448352443.54.0.731172452763.issue25718@psf.upfronthosting.co.za> |
2015-11-24 08:07:23 | arigo | link | issue25718 messages |
2015-11-24 08:07:23 | arigo | create | |
|