]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-152492 Allow `OrderedDict.update` to work with `frozendict` (GH-152494...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 29 Jun 2026 20:20:08 +0000 (22:20 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Jun 2026 20:20:08 +0000 (20:20 +0000)
gh-152492 Allow `OrderedDict.update` to work with `frozendict` (GH-152494)
(cherry picked from commit 0a29d8408cfdd9a66f2b65745a3ae1cda022775c)

Co-authored-by: da-woods <dw-git@d-woods.co.uk>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
Lib/test/test_ordered_dict.py
Misc/NEWS.d/next/Core_and_Builtins/2026-06-28-14-31-03.gh-issue-152492._09Zee.rst [new file with mode: 0644]
Objects/odictobject.c

index 84bb3fdfbaaa6e7e09ba83676f3c72ad15e52848..ac24110cf63e823b26ffa1dc5a5349966ae0e7ff 100644 (file)
@@ -74,6 +74,9 @@ class OrderedDictTests:
         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 @@ class OrderedDictTests:
         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 (file)
index 0000000..16cb5a2
--- /dev/null
@@ -0,0 +1 @@
+:type:`collections.OrderedDict` ``update`` method can now accept :type:`frozendict` as an argument.
index 33914cdffb1dcc58fa20e1fc9bd2bcae602af1d8..6f10c4863856d9f0414b5c5a7649bb22d1272003 100644 (file)
@@ -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;
     }
 
@@ -2369,7 +2369,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)