gh-149534: Fix unification of defaultdict and frozendict with | (#149539)

This commit is contained in:
sobolevn 2026-06-01 16:26:49 +03:00 committed by GitHub
parent c98773633c
commit cc0269334f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

View file

@ -186,6 +186,18 @@ def test_union(self):
with self.assertRaises(TypeError):
i |= None
# frozendict
i_fd = i | frozendict(s)
self.assertIs(type(i_fd), defaultdict)
self.assertIs(i_fd.default_factory, int)
self.assertDictEqual(i_fd, {1: "one", 2: 2, 0: "zero"})
self.assertEqual(list(i_fd), [1, 2, 0])
fd_i = frozendict(s) | i
self.assertIs(type(fd_i), frozendict)
self.assertEqual(fd_i, {1: "one", 2: 2, 0: "zero"})
self.assertEqual(list(fd_i), [0, 1, 2])
def test_factory_conflict_with_set_value(self):
key = "conflict_test"
count = 0

View file

@ -0,0 +1 @@
Fix merging of :class:`collections.defaultdict` and :class:`frozendict`.

View file

@ -2421,7 +2421,7 @@ defdict_or(PyObject* left, PyObject* right)
self = right;
other = left;
}
if (!PyDict_Check(other)) {
if (!PyAnyDict_Check(other)) {
Py_RETURN_NOTIMPLEMENTED;
}
// Like copy(), this calls the object's class.