summaryrefslogtreecommitdiffstats
path: root/Lib/collections
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2020-02-25 03:47:34 (GMT)
committerGitHub <noreply@github.com>2020-02-25 03:47:34 (GMT)
commiteb8ac57af26c4eb96a8230eba7492ce5ceef7886 (patch)
treea19866e216c6c7ef6c75de0f653bf653cc55ac67 /Lib/collections
parentba22e8f174309979d90047c5dc64fcb63bc2c32e (diff)
downloadcpython-eb8ac57af26c4eb96a8230eba7492ce5ceef7886.zip
cpython-eb8ac57af26c4eb96a8230eba7492ce5ceef7886.tar.gz
cpython-eb8ac57af26c4eb96a8230eba7492ce5ceef7886.tar.bz2
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 178cdb1..1aa7d10 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__)