https://github.com/python/cpython/commit/0a29d8408cfdd9a66f2b65745a3ae1cda022775c commit: 0a29d8408cfdd9a66f2b65745a3ae1cda022775c branch: main author: da-woods <[email protected]> committer: sobolevn <[email protected]> date: 2026-06-29T22:54:22+03:00 summary:
gh-152492 Allow `OrderedDict.update` to work with `frozendict` (#152494) Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: sobolevn <[email protected]> files: A Misc/NEWS.d/next/Core_and_Builtins/2026-06-28-14-31-03.gh-issue-152492._09Zee.rst M Lib/test/test_ordered_dict.py M Objects/odictobject.c diff --git a/Lib/test/test_ordered_dict.py b/Lib/test/test_ordered_dict.py index 84bb3fdfbaaa6e..ac24110cf63e82 100644 --- a/Lib/test/test_ordered_dict.py +++ b/Lib/test/test_ordered_dict.py @@ -74,6 +74,9 @@ def test_update(self): od.update(dict(pairs)) self.assertEqual(sorted(od.items()), pairs) # dict input od = OrderedDict() + od.update(frozendict(pairs)) + self.assertEqual(sorted(od.items()), pairs) # frozendict input + od = OrderedDict() od.update(**dict(pairs)) self.assertEqual(sorted(od.items()), pairs) # kwds input od = OrderedDict() @@ -288,9 +291,11 @@ def test_equality(self): pairs = pairs[2:] + pairs[:2] od2 = OrderedDict(pairs) self.assertNotEqual(od1, od2) # different order implies inequality - # comparison to regular dict is not order sensitive + # comparison to regular (frozen)dict is not order sensitive self.assertEqual(od1, dict(od2)) self.assertEqual(dict(od2), od1) + self.assertEqual(od1, frozendict(od2)) + self.assertEqual(frozendict(od1), od2) # different length implied inequality self.assertNotEqual(od1, OrderedDict(pairs[:-1])) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-28-14-31-03.gh-issue-152492._09Zee.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-28-14-31-03.gh-issue-152492._09Zee.rst new file mode 100644 index 00000000000000..16cb5a205c908a --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-28-14-31-03.gh-issue-152492._09Zee.rst @@ -0,0 +1 @@ +:type:`collections.OrderedDict` ``update`` method can now accept :type:`frozendict` as an argument. diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 6d7e436ff00867..c51fd4b7195da4 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1503,7 +1503,7 @@ odict_tp_clear(PyObject *op) static PyObject * odict_richcompare_lock_held(PyObject *v, PyObject *w, int op) { - if (!PyODict_Check(v) || !PyDict_Check(w)) { + if (!PyODict_Check(v) || !PyAnyDict_Check(w)) { Py_RETURN_NOTIMPLEMENTED; } @@ -2370,7 +2370,7 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs) } /* now handle kwargs */ - assert(kwargs == NULL || PyDict_Check(kwargs)); + assert(kwargs == NULL || PyAnyDict_Check(kwargs)); if (kwargs != NULL && PyDict_GET_SIZE(kwargs)) { PyObject *items = PyDict_Items(kwargs); if (items == NULL) _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
