diff options
author | Brandt Bucher <brandtbucher@gmail.com> | 2020-03-13 16:06:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-13 16:06:04 (GMT) |
commit | 6d674a1bf456945eb758e85c11484a9f1494f2b4 (patch) | |
tree | 667d42a0fb1b9d939cc8a890e5d07351c10f18aa /Lib/collections | |
parent | d648ef10c5c7659ed3c9f34d5c751dc55e2c6007 (diff) | |
download | cpython-6d674a1bf456945eb758e85c11484a9f1494f2b4.zip cpython-6d674a1bf456945eb758e85c11484a9f1494f2b4.tar.gz cpython-6d674a1bf456945eb758e85c11484a9f1494f2b4.tar.bz2 |
bpo-36144: OrderedDict Union (PEP 584) (#18967)
Diffstat (limited to 'Lib/collections')
-rw-r--r-- | Lib/collections/__init__.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 1aa7d10..18255da 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -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 |