Skip to content

Commit 722f8fd

Browse files
authored
Merge pull request #3947 from jopemachine/edit-defaultdict
Add `or`, `ror` and`ior` to `defaultdict`
2 parents 6ebb3f5 + 9c2a504 commit 722f8fd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Lib/collections/_defaultdict.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,20 @@ def __reduce__(self):
3939
args = ()
4040
return type(self), args, None, None, iter(self.items())
4141

42+
def __or__(self, other):
43+
if not isinstance(other, dict):
44+
return NotImplemented
45+
46+
new = defaultdict(self.default_factory, self)
47+
new.update(other)
48+
return new
49+
50+
def __ror__(self, other):
51+
if not isinstance(other, dict):
52+
return NotImplemented
53+
54+
new = defaultdict(self.default_factory, other)
55+
new.update(self)
56+
return new
57+
4258
defaultdict.__module__ = 'collections'

Lib/test/test_defaultdict.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ def test_pickling(self):
150150
o = pickle.loads(s)
151151
self.assertEqual(d, o)
152152

153-
# TODO: RUSTPYTHON
154-
@unittest.expectedFailure
155153
def test_union(self):
156154
i = defaultdict(int, {1: 1, 2: 2})
157155
s = defaultdict(str, {0: "zero", 1: "one"})

0 commit comments

Comments
 (0)