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

Side by Side Diff: Lib/collections/__init__.py

Issue 17900: Recursive OrderedDict pickling (Closed)
Patch Set: Created 5 years, 1 month ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_collections.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 __all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList', 1 __all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList',
2 'UserString', 'Counter', 'OrderedDict', 'ChainMap'] 2 'UserString', 'Counter', 'OrderedDict', 'ChainMap']
3 3
4 # For backwards compatibility, continue to make the collections ABCs 4 # For backwards compatibility, continue to make the collections ABCs
5 # available through the collections module. 5 # available through the collections module.
6 from _collections_abc import * 6 from _collections_abc import *
7 import _collections_abc 7 import _collections_abc
8 __all__ += _collections_abc.__all__ 8 __all__ += _collections_abc.__all__
9 9
10 from _collections import deque, defaultdict 10 from _collections import deque, defaultdict
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 self[key] = default 219 self[key] = default
220 return default 220 return default
221 221
222 @_recursive_repr() 222 @_recursive_repr()
223 def __repr__(self): 223 def __repr__(self):
224 'od.__repr__() <==> repr(od)' 224 'od.__repr__() <==> repr(od)'
225 if not self: 225 if not self:
226 return '%s()' % (self.__class__.__name__,) 226 return '%s()' % (self.__class__.__name__,)
227 return '%s(%r)' % (self.__class__.__name__, list(self.items())) 227 return '%s(%r)' % (self.__class__.__name__, list(self.items()))
228 228
229 def __reduce__(self): 229 def __reduce_ex__(self, proto):
230 'Return state information for pickling' 230 'Return state information for pickling'
231 inst_dict = vars(self).copy() 231 inst_dict = vars(self).copy()
232 for k in vars(OrderedDict()): 232 for k in vars(OrderedDict()):
233 inst_dict.pop(k, None) 233 inst_dict.pop(k, None)
234 if proto < 3:
235 # Support PyYAML's dump() feature.
236 # In yaml, lists are native but tuples are not.
237 items = [[k, self[k]] for k in self]
238 if inst_dict:
239 return (self.__class__, (items,), inst_dict)
240 return self.__class__, (items,)
234 return self.__class__, (), inst_dict or None, None, iter(self.items()) 241 return self.__class__, (), inst_dict or None, None, iter(self.items())
242
243 def __reduce__(self):
244 'Return state information for pickling'
245 return self.__reduce_ex__(0)
235 246
236 def copy(self): 247 def copy(self):
237 'od.copy() -> a shallow copy of od' 248 'od.copy() -> a shallow copy of od'
238 return self.__class__(self) 249 return self.__class__(self)
239 250
240 @classmethod 251 @classmethod
241 def fromkeys(cls, iterable, value=None): 252 def fromkeys(cls, iterable, value=None):
242 '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S. 253 '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
243 If not specified, the value defaults to None. 254 If not specified, the value defaults to None.
244 255
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 def splitlines(self, keepends=False): return self.data.splitlines(keepends) 1163 def splitlines(self, keepends=False): return self.data.splitlines(keepends)
1153 def startswith(self, prefix, start=0, end=_sys.maxsize): 1164 def startswith(self, prefix, start=0, end=_sys.maxsize):
1154 return self.data.startswith(prefix, start, end) 1165 return self.data.startswith(prefix, start, end)
1155 def strip(self, chars=None): return self.__class__(self.data.strip(chars)) 1166 def strip(self, chars=None): return self.__class__(self.data.strip(chars))
1156 def swapcase(self): return self.__class__(self.data.swapcase()) 1167 def swapcase(self): return self.__class__(self.data.swapcase())
1157 def title(self): return self.__class__(self.data.title()) 1168 def title(self): return self.__class__(self.data.title())
1158 def translate(self, *args): 1169 def translate(self, *args):
1159 return self.__class__(self.data.translate(*args)) 1170 return self.__class__(self.data.translate(*args))
1160 def upper(self): return self.__class__(self.data.upper()) 1171 def upper(self): return self.__class__(self.data.upper())
1161 def zfill(self, width): return self.__class__(self.data.zfill(width)) 1172 def zfill(self, width): return self.__class__(self.data.zfill(width))
OLDNEW
« 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+