diff --git a/Lib/collections/_defaultdict.py b/Lib/collections/_defaultdict.py index 007ca9104e..b9c6c49613 100644 --- a/Lib/collections/_defaultdict.py +++ b/Lib/collections/_defaultdict.py @@ -39,4 +39,20 @@ def __reduce__(self): args = () return type(self), args, None, None, iter(self.items()) + def __or__(self, other): + if not isinstance(other, dict): + return NotImplemented + + new = defaultdict(self.default_factory, self) + new.update(other) + return new + + def __ror__(self, other): + if not isinstance(other, dict): + return NotImplemented + + new = defaultdict(self.default_factory, other) + new.update(self) + return new + defaultdict.__module__ = 'collections' diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py index 65376a37ef..68fc449780 100644 --- a/Lib/test/test_defaultdict.py +++ b/Lib/test/test_defaultdict.py @@ -150,8 +150,6 @@ def test_pickling(self): o = pickle.loads(s) self.assertEqual(d, o) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_union(self): i = defaultdict(int, {1: 1, 2: 2}) s = defaultdict(str, {0: "zero", 1: "one"})