bpo-36144: Add union operators to WeakValueDictionary584 (#19127)

This commit is contained in:
Curtis Bucher 2020-03-24 18:51:29 -07:00 committed by GitHub
parent 37fcbb65d4
commit 8f1ed21ecf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 0 deletions

View file

@ -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.