aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2018-02-11 00:30:31 -0800
committerGitHub <noreply@github.com>2018-02-11 00:30:31 -0800
commit3793f95f98c3112ce447288a5bf9899eb9e35423 (patch)
tree7c7b62ce2d585c9ec90ed1b502dd4881bd37e739 /Lib/collections
parentbpo-32800: Update link to w3c doc for xml default namespaces (GH-5609) (diff)
downloadcpython-3793f95f98c3112ce447288a5bf9899eb9e35423.tar.gz
cpython-3793f95f98c3112ce447288a5bf9899eb9e35423.tar.bz2
cpython-3793f95f98c3112ce447288a5bf9899eb9e35423.zip
bpo-32792: Preserve mapping order in ChainMap() (GH-5586)
Diffstat (limited to 'Lib/collections')
-rw-r--r--Lib/collections/__init__.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index f0b41fd9d10..9a753db71ca 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -920,7 +920,10 @@ class ChainMap(_collections_abc.MutableMapping):
return len(set().union(*self.maps)) # reuses stored hash values if possible
def __iter__(self):
- return iter(set().union(*self.maps))
+ d = {}
+ for mapping in reversed(self.maps):
+ d.update(mapping) # reuses stored hash values if possible
+ return iter(d)
def __contains__(self, key):
return any(key in m for m in self.maps)