bpo-36144: OrderedDict Union (PEP 584) (#18967)

This commit is contained in:
Brandt Bucher 2020-03-13 09:06:04 -07:00 committed by GitHub
parent d648ef10c5
commit 6d674a1bf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 188 additions and 76 deletions

View file

@ -293,6 +293,24 @@ class OrderedDict(dict):
return dict.__eq__(self, other) and all(map(_eq, self, other))
return dict.__eq__(self, other)
def __ior__(self, other):
self.update(other)
return self
def __or__(self, other):
if not isinstance(other, dict):
return NotImplemented
new = self.__class__(self)
new.update(other)
return new
def __ror__(self, other):
if not isinstance(other, dict):
return NotImplemented
new = self.__class__(other)
new.update(self)
return new
try:
from _collections import OrderedDict