summaryrefslogtreecommitdiff
path: root/Lib/weakref.py
diff options
context:
space:
mode:
authorCurtis Bucher <cpbucher5@gmail.com>2020-03-24 18:51:29 -0700
committerGitHub <noreply@github.com>2020-03-24 18:51:29 -0700
commit8f1ed21ecf57cc8b8095d9d1058af2b9b3ed0413 (patch)
treed74da03f51570b5a14c1e0a718cfdf47eaa6148d /Lib/weakref.py
parent37fcbb65d4589fbb5a72153e9338cf8e6495f64f (diff)
downloadcpython-git-8f1ed21ecf57cc8b8095d9d1058af2b9b3ed0413.tar.gz
bpo-36144: Add union operators to WeakValueDictionary584 (#19127)
Diffstat (limited to 'Lib/weakref.py')
-rw-r--r--Lib/weakref.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py
index 759ad6dfa3..5fa851dd6d 100644
--- a/Lib/weakref.py
+++ b/Lib/weakref.py
@@ -310,6 +310,25 @@ class WeakValueDictionary(_collections_abc.MutableMapping):
self._commit_removals()
return list(self.data.values())
+ def __ior__(self, other):
+ self.update(other)
+ return self
+
+ def __or__(self, other):
+ if isinstance(other, _collections_abc.Mapping):
+ c = self.copy()
+ c.update(other)
+ return c
+ return NotImplemented
+
+ def __ror__(self, other):
+ if isinstance(other, _collections_abc.Mapping):
+ c = self.__class__()
+ c.update(other)
+ c.update(self)
+ return c
+ return NotImplemented
+
class KeyedRef(ref):
"""Specialized reference that includes a key corresponding to the value.