diff -r 9c84dd9b3bce Lib/collections/__init__.py --- a/Lib/collections/__init__.py Fri May 03 21:22:25 2013 +0300 +++ b/Lib/collections/__init__.py Fri May 03 22:36:34 2013 +0300 @@ -199,13 +199,10 @@ def __reduce__(self): 'Return state information for pickling' - items = [[k, self[k]] for k in self] inst_dict = vars(self).copy() for k in vars(OrderedDict()): inst_dict.pop(k, None) - if inst_dict: - return (self.__class__, (items,), inst_dict) - return self.__class__, (items,) + return self.__class__, (), inst_dict or None, None, iter(self.items()) def copy(self): 'od.copy() -> a shallow copy of od' diff -r 9c84dd9b3bce Lib/test/test_collections.py --- a/Lib/test/test_collections.py Fri May 03 21:22:25 2013 +0300 +++ b/Lib/test/test_collections.py Fri May 03 22:36:34 2013 +0300 @@ -1244,9 +1244,18 @@ # 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) + self.assertIsNone(od.__reduce__()[2]) od.x = 10 - self.assertEqual(len(od.__reduce__()), 3) + self.assertIsNotNone(od.__reduce__()[2]) + + def test_pickle_recursive(self): + od = OrderedDict() + od[1] = od + for proto in range(-1, 3): + dup = pickle.loads(pickle.dumps(od, proto)) + self.assertIsNot(dup, od) + self.assertEqual(list(dup.keys()), [1]) + self.assertIs(dup[1], dup) def test_repr(self): od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])