mirror of
https://github.com/python/cpython.git
synced 2026-06-04 16:50:51 +00:00
gh-149534: Fix unification of defaultdict and frozendict with | (#149539)
This commit is contained in:
parent
c98773633c
commit
cc0269334f
3 changed files with 14 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Fix merging of :class:`collections.defaultdict` and :class:`frozendict`.
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue