Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/collections/_defaultdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 0 additions & 2 deletions Lib/test/test_defaultdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down