Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5781)

Unified Diff: Lib/collections/__init__.py

Issue 17900: Recursive OrderedDict pickling (Closed)
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/test/test_collections.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/collections/__init__.py Sat Nov 01 07:40:22 2014 -0700
+++ b/Lib/collections/__init__.py Sun Nov 02 16:51:38 2014 +0200
@@ -226,13 +226,24 @@ class OrderedDict(dict):
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, list(self.items()))
- def __reduce__(self):
+ def __reduce_ex__(self, proto):
'Return state information for pickling'
inst_dict = vars(self).copy()
for k in vars(OrderedDict()):
inst_dict.pop(k, None)
+ if proto < 3:
+ # Support PyYAML's dump() feature.
+ # In yaml, lists are native but tuples are not.
+ items = [[k, self[k]] for k in self]
+ 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 __reduce__(self):
+ 'Return state information for pickling'
+ return self.__reduce_ex__(0)
+
def copy(self):
'od.copy() -> a shallow copy of od'
return self.__class__(self)
« no previous file with comments | « no previous file | Lib/test/test_collections.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+