diff options
author | Curtis Bucher <cpbucher5@gmail.com> | 2020-03-23 20:49:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-23 20:49:46 (GMT) |
commit | 25e580a73c163f472fdeb5489bebef85da21655c (patch) | |
tree | ae7ee5d6817eb0efd91e6fd2db0237071fb05b06 /Lib/weakref.py | |
parent | 8dd1792c680caaf94a00cead82b238238f419172 (diff) | |
download | cpython-25e580a73c163f472fdeb5489bebef85da21655c.zip cpython-25e580a73c163f472fdeb5489bebef85da21655c.tar.gz cpython-25e580a73c163f472fdeb5489bebef85da21655c.tar.bz2 |
bpo-36144: Add union operators to WeakKeyDictionary (#19106)
Diffstat (limited to 'Lib/weakref.py')
-rw-r--r-- | Lib/weakref.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py index e3c2ce2..759ad6d 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -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 |