aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2020-02-24 19:47:34 -0800
committerGitHub <noreply@github.com>2020-02-24 19:47:34 -0800
commiteb8ac57af26c4eb96a8230eba7492ce5ceef7886 (patch)
treea19866e216c6c7ef6c75de0f653bf653cc55ac67 /Lib/collections
parentbpo-30566: Fix IndexError when using punycode codec (GH-18632) (diff)
downloadcpython-eb8ac57af26c4eb96a8230eba7492ce5ceef7886.tar.gz
cpython-eb8ac57af26c4eb96a8230eba7492ce5ceef7886.tar.bz2
cpython-eb8ac57af26c4eb96a8230eba7492ce5ceef7886.zip
bpo-36144: Dictionary Union (PEP 584) (#12088)
Diffstat (limited to 'Lib/collections')
-rw-r--r--Lib/collections/__init__.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 178cdb1fa5b..1aa7d10ad22 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -994,6 +994,26 @@ class UserDict(_collections_abc.MutableMapping):
# Now, add the methods in dicts but not in MutableMapping
def __repr__(self): return repr(self.data)
+
+ def __or__(self, other):
+ if isinstance(other, UserDict):
+ return self.__class__(self.data | other.data)
+ if isinstance(other, dict):
+ return self.__class__(self.data | other)
+ return NotImplemented
+ def __ror__(self, other):
+ if isinstance(other, UserDict):
+ return self.__class__(other.data | self.data)
+ if isinstance(other, dict):
+ return self.__class__(other | self.data)
+ return NotImplemented
+ def __ior__(self, other):
+ if isinstance(other, UserDict):
+ self.data |= other.data
+ else:
+ self.data |= other
+ return self
+
def __copy__(self):
inst = self.__class__.__new__(self.__class__)
inst.__dict__.update(self.__dict__)