mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-36144: Add union operators to WeakKeyDictionary (#19106)
This commit is contained in:
parent
8dd1792c68
commit
25e580a73c
4 changed files with 60 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue