bpo-36144: Add union operators to WeakKeyDictionary (#19106)

This commit is contained in:
Curtis Bucher 2020-03-23 13:49:46 -07:00 committed by GitHub
parent 8dd1792c68
commit 25e580a73c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 0 deletions

View file

@ -488,6 +488,25 @@ class WeakKeyDictionary(_collections_abc.MutableMapping):
if len(kwargs):
self.update(kwargs)
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 finalize:
"""Class for finalization of weakrefable objects