mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-36144: Dictionary Union (PEP 584) (#12088)
This commit is contained in:
parent
ba22e8f174
commit
eb8ac57af2
4 changed files with 107 additions and 18 deletions
|
@ -994,6 +994,26 @@ class UserDict(_collections_abc.MutableMapping):
|
|||
|
||||
# Now, add the methods in dicts but not in MutableMapping
|
||||
def __repr__(self): return repr(self.data)
|
||||
|
||||
def __or__(self, other):
|
||||
if isinstance(other, UserDict):
|
||||
return self.__class__(self.data | other.data)
|
||||
if isinstance(other, dict):
|
||||
return self.__class__(self.data | other)
|
||||
return NotImplemented
|
||||
def __ror__(self, other):
|
||||
if isinstance(other, UserDict):
|
||||
return self.__class__(other.data | self.data)
|
||||
if isinstance(other, dict):
|
||||
return self.__class__(other | self.data)
|
||||
return NotImplemented
|
||||
def __ior__(self, other):
|
||||
if isinstance(other, UserDict):
|
||||
self.data |= other.data
|
||||
else:
|
||||
self.data |= other
|
||||
return self
|
||||
|
||||
def __copy__(self):
|
||||
inst = self.__class__.__new__(self.__class__)
|
||||
inst.__dict__.update(self.__dict__)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue