diff options
Diffstat (limited to 'Lib/collections')
-rw-r--r-- | Lib/collections/__init__.py | 18 | ||||
-rw-r--r-- | Lib/collections/abc.py | 5 |
2 files changed, 12 insertions, 11 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 254409b..e1a075c 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -12,7 +12,7 @@ from operator import itemgetter as _itemgetter, eq as _eq from keyword import iskeyword as _iskeyword import sys as _sys import heapq as _heapq -from weakref import proxy as _proxy +from _weakref import proxy as _proxy from itertools import repeat as _repeat, chain as _chain, starmap as _starmap from reprlib import recursive_repr as _recursive_repr @@ -199,13 +199,10 @@ class OrderedDict(dict): 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' @@ -822,9 +819,14 @@ class ChainMap(MutableMapping): __copy__ = copy - def new_child(self): # like Django's Context.push() - 'New ChainMap with a new dict followed by all previous maps.' - return self.__class__({}, *self.maps) + def new_child(self, m=None): # like Django's Context.push() + ''' + New ChainMap with a new map followed by all previous maps. If no + map is provided, an empty dict is used. + ''' + if m is None: + m = {} + return self.__class__(m, *self.maps) @property def parents(self): # like Django's Context.pop() diff --git a/Lib/collections/abc.py b/Lib/collections/abc.py index 7939268..a8681ea 100644 --- a/Lib/collections/abc.py +++ b/Lib/collections/abc.py @@ -454,8 +454,7 @@ class KeysView(MappingView, Set): return key in self._mapping def __iter__(self): - for key in self._mapping: - yield key + yield from self._mapping KeysView.register(dict_keys) @@ -663,7 +662,7 @@ class MutableSequence(Sequence): __slots__ = () - """All the operations on a read-only sequence. + """All the operations on a read-write sequence. Concrete subclasses must provide __new__ or __init__, __getitem__, __setitem__, __delitem__, __len__, and insert(). |