mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Issue #17900: Allowed pickling of recursive OrderedDicts. Decreased pickled
size and pickling time.
This commit is contained in:
parent
b10c71daa2
commit
3ee6dabf5b
3 changed files with 15 additions and 6 deletions
|
@ -1245,9 +1245,18 @@ 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)
|
||||
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, pickle.HIGHEST_PROTOCOL + 1):
|
||||
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)])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue