Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3.6 Changeset: r93371:ce0523b30644 Date: 2017-12-11 19:14 +0100 http://bitbucket.org/pypy/pypy/changeset/ce0523b30644/
Log: CPython Issue26482: can pickle recursive deque objects. diff --git a/lib_pypy/_collections.py b/lib_pypy/_collections.py --- a/lib_pypy/_collections.py +++ b/lib_pypy/_collections.py @@ -323,7 +323,7 @@ self.rotate(-index) def __reduce_ex__(self, proto): - return type(self), (list(self), self.maxlen) + return type(self), ((), self.maxlen), None, iter(self) __hash__ = None diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py --- a/pypy/module/_collections/interp_deque.py +++ b/pypy/module/_collections/interp_deque.py @@ -491,23 +491,14 @@ "Return state information for pickling." space = self.space w_type = space.type(self) - w_dict = space.findattr(self, space.newtext('__dict__')) - w_list = space.call_function(space.w_list, self) - if w_dict is None: - if self.maxlen == sys.maxint: - result = [ - w_type, space.newtuple([w_list])] - else: - result = [ - w_type, space.newtuple([w_list, space.newint(self.maxlen)])] + w_dict = space.findattr(self, space.newtext('__dict__')) or space.w_None + w_it = space.iter(self) + if self.maxlen == sys.maxint: + w_lentuple = space.newtuple([]) else: - if self.maxlen == sys.maxint: - w_len = space.w_None - else: - w_len = space.newint(self.maxlen) - result = [ - w_type, space.newtuple([w_list, w_len]), w_dict] - return space.newtuple(result) + w_lentuple = space.newtuple([space.newtuple([]), + space.newint(self.maxlen)]) + return space.newtuple([w_type, w_lentuple, w_dict, w_it]) def get_maxlen(space, self): if self.maxlen == sys.maxint: diff --git a/pypy/module/_collections/test/test_deque.py b/pypy/module/_collections/test/test_deque.py --- a/pypy/module/_collections/test/test_deque.py +++ b/pypy/module/_collections/test/test_deque.py @@ -264,25 +264,25 @@ # d = deque('hello world') r = d.__reduce__() - assert r == (deque, (list('hello world'),)) + assert r[:3] == (deque, (), None) # d = deque('hello world', 42) r = d.__reduce__() - assert r == (deque, (list('hello world'), 42)) + assert r[:3] == (deque, ((), 42), None) # class D(deque): pass d = D('hello world') d.a = 5 r = d.__reduce__() - assert r == (D, (list('hello world'), None), {'a': 5}) + assert r[:3] == (D, (), {'a': 5}) # class D(deque): pass d = D('hello world', 42) d.a = 5 r = d.__reduce__() - assert r == (D, (list('hello world'), 42), {'a': 5}) + assert r[:3] == (D, ((), 42), {'a': 5}) def test_copy(self): from _collections import deque _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit