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.
This commit is contained in:
Alexandre Vassalotti 2009-06-12 23:03:35 +00:00
parent 450ae573bc
commit cb73bdac95
2 changed files with 6 additions and 8 deletions

View file

@ -99,16 +99,14 @@ class OrderedDict(dict, MutableMapping):
def __reduce__(self): def __reduce__(self):
'Return state information for pickling' 'Return state information for pickling'
dictitems = self.iteritems() items = [[k, self[k]] for k in self]
tmp = self.__map, self.__root tmp = self.__map, self.__root
del self.__map, self.__root del self.__map, self.__root
inst_dict = vars(self).copy() inst_dict = vars(self).copy()
self.__map, self.__root = tmp self.__map, self.__root = tmp
# Set the state item to None when the dictionary is empty. This saves if inst_dict:
# about 2 opcodes when the object is pickled. return (self.__class__, (items,), inst_dict)
if not inst_dict: return self.__class__, (items,)
inst_dict = None
return (self.__class__, (), inst_dict, None, dictitems)
setdefault = MutableMapping.setdefault setdefault = MutableMapping.setdefault
update = MutableMapping.update update = MutableMapping.update

View file

@ -795,9 +795,9 @@ class TestOrderedDict(unittest.TestCase):
# do not save instance dictionary if not needed # do not save instance dictionary if not needed
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)] pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
od = OrderedDict(pairs) od = OrderedDict(pairs)
self.assertEqual(len(od.__reduce__()), 2)
od.x = 10 od.x = 10
self.assertGreaterEqual(len(od.__reduce__()), 2) self.assertEqual(len(od.__reduce__()), 3)
self.assertLessEqual(len(od.__reduce__()), 5)
def test_repr(self): def test_repr(self):
od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]) od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])