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