From cb73bdac9565e7d4a9133635f802f446a915ca88 Mon Sep 17 00:00:00 2001 From: Alexandre Vassalotti Date: Fri, 12 Jun 2009 23:03:35 +0000 Subject: 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. --- Lib/collections.py | 10 ++++------ Lib/test/test_collections.py | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Lib/collections.py b/Lib/collections.py index 202b8b2..1e807af 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -99,16 +99,14 @@ class OrderedDict(dict, MutableMapping): def __reduce__(self): 'Return state information for pickling' - dictitems = self.iteritems() + items = [[k, self[k]] for k in self] tmp = self.__map, self.__root del self.__map, self.__root inst_dict = vars(self).copy() self.__map, self.__root = tmp - # Set the state item to None when the dictionary is empty. This saves - # about 2 opcodes when the object is pickled. - if not inst_dict: - inst_dict = None - return (self.__class__, (), inst_dict, None, dictitems) + if inst_dict: + return (self.__class__, (items,), inst_dict) + return self.__class__, (items,) setdefault = MutableMapping.setdefault update = MutableMapping.update diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index b108f95..1c49876 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -795,9 +795,9 @@ class TestOrderedDict(unittest.TestCase): # do not save instance dictionary if not needed pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)] od = OrderedDict(pairs) + self.assertEqual(len(od.__reduce__()), 2) od.x = 10 - self.assertGreaterEqual(len(od.__reduce__()), 2) - self.assertLessEqual(len(od.__reduce__()), 5) + self.assertEqual(len(od.__reduce__()), 3) def test_repr(self): od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]) -- cgit v0.12