Skip to content

Commit 7bd141b

Browse files
committed
Revert r73401 per Raymond Hettinger's request.
The rational is the change might cause imcompatiblity problems with PyYAML. In addition, Raymond wants to kept the different versions of collections synchronized across Python versions.
1 parent 5649153 commit 7bd141b

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

Lib/collections.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,14 @@ def __reversed__(self):
9999

100100
def __reduce__(self):
101101
'Return state information for pickling'
102-
dictitems = self.iteritems()
102+
items = [[k, self[k]] for k in self]
103103
tmp = self.__map, self.__root
104104
del self.__map, self.__root
105105
inst_dict = vars(self).copy()
106106
self.__map, self.__root = tmp
107-
# Set the state item to None when the dictionary is empty. This saves
108-
# about 2 opcodes when the object is pickled.
109-
if not inst_dict:
110-
inst_dict = None
111-
return (self.__class__, (), inst_dict, None, dictitems)
107+
if inst_dict:
108+
return (self.__class__, (items,), inst_dict)
109+
return self.__class__, (items,)
112110

113111
setdefault = MutableMapping.setdefault
114112
update = MutableMapping.update

Lib/test/test_collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,9 @@ def test_reduce_not_too_fat(self):
795795
# do not save instance dictionary if not needed
796796
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
797797
od = OrderedDict(pairs)
798+
self.assertEqual(len(od.__reduce__()), 2)
798799
od.x = 10
799-
self.assertGreaterEqual(len(od.__reduce__()), 2)
800-
self.assertLessEqual(len(od.__reduce__()), 5)
800+
self.assertEqual(len(od.__reduce__()), 3)
801801

802802
def test_repr(self):
803803
od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])

0 commit comments

Comments
 (0)