Skip to content

Commit ec2bc12

Browse files
gh-145056: Add support for merging collections.UserDict and frozendict (GH-146465)
1 parent 7278904 commit ec2bc12

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Lib/collections/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,14 +1216,14 @@ def __repr__(self):
12161216
def __or__(self, other):
12171217
if isinstance(other, UserDict):
12181218
return self.__class__(self.data | other.data)
1219-
if isinstance(other, dict):
1219+
if isinstance(other, (dict, frozendict)):
12201220
return self.__class__(self.data | other)
12211221
return NotImplemented
12221222

12231223
def __ror__(self, other):
12241224
if isinstance(other, UserDict):
12251225
return self.__class__(other.data | self.data)
1226-
if isinstance(other, dict):
1226+
if isinstance(other, (dict, frozendict)):
12271227
return self.__class__(other | self.data)
12281228
return NotImplemented
12291229

Lib/test/test_userdict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class G(collections.UserDict):
245245
test_repr_deep = mapping_tests.TestHashMappingProtocol.test_repr_deep
246246

247247
def test_mixed_or(self):
248-
for t in UserDict, dict, types.MappingProxyType:
248+
for t in UserDict, dict, frozendict, types.MappingProxyType:
249249
with self.subTest(t.__name__):
250250
u = UserDict({0: 'a', 1: 'b'}) | t({1: 'c', 2: 'd'})
251251
self.assertEqual(u, {0: 'a', 1: 'c', 2: 'd'})
@@ -276,7 +276,7 @@ def test_mixed_or(self):
276276
self.assertIs(type(u), UserDictSubclass)
277277

278278
def test_mixed_ior(self):
279-
for t in UserDict, dict, types.MappingProxyType:
279+
for t in UserDict, dict, frozendict, types.MappingProxyType:
280280
with self.subTest(t.__name__):
281281
u = u2 = UserDict({0: 'a', 1: 'b'})
282282
u |= t({1: 'c', 2: 'd'})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for merging :class:`collections.UserDict` and :class:`frozendict`.

0 commit comments

Comments
 (0)