Skip to content

Commit 0b273d8

Browse files
miss-islingtonda-woodsblurb-it[bot]sobolevn
authored
[3.15] gh-152492 Allow OrderedDict.update to work with frozendict (GH-152494) (#152630)
gh-152492 Allow `OrderedDict.update` to work with `frozendict` (GH-152494) (cherry picked from commit 0a29d84) 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>
1 parent 93c71c7 commit 0b273d8

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

Lib/test/test_ordered_dict.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def test_update(self):
7474
od.update(dict(pairs))
7575
self.assertEqual(sorted(od.items()), pairs) # dict input
7676
od = OrderedDict()
77+
od.update(frozendict(pairs))
78+
self.assertEqual(sorted(od.items()), pairs) # frozendict input
79+
od = OrderedDict()
7780
od.update(**dict(pairs))
7881
self.assertEqual(sorted(od.items()), pairs) # kwds input
7982
od = OrderedDict()
@@ -288,9 +291,11 @@ def test_equality(self):
288291
pairs = pairs[2:] + pairs[:2]
289292
od2 = OrderedDict(pairs)
290293
self.assertNotEqual(od1, od2) # different order implies inequality
291-
# comparison to regular dict is not order sensitive
294+
# comparison to regular (frozen)dict is not order sensitive
292295
self.assertEqual(od1, dict(od2))
293296
self.assertEqual(dict(od2), od1)
297+
self.assertEqual(od1, frozendict(od2))
298+
self.assertEqual(frozendict(od1), od2)
294299
# different length implied inequality
295300
self.assertNotEqual(od1, OrderedDict(pairs[:-1]))
296301

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:type:`collections.OrderedDict` ``update`` method can now accept :type:`frozendict` as an argument.

Objects/odictobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ odict_tp_clear(PyObject *op)
15031503
static PyObject *
15041504
odict_richcompare_lock_held(PyObject *v, PyObject *w, int op)
15051505
{
1506-
if (!PyODict_Check(v) || !PyDict_Check(w)) {
1506+
if (!PyODict_Check(v) || !PyAnyDict_Check(w)) {
15071507
Py_RETURN_NOTIMPLEMENTED;
15081508
}
15091509

@@ -2369,7 +2369,7 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
23692369
}
23702370

23712371
/* now handle kwargs */
2372-
assert(kwargs == NULL || PyDict_Check(kwargs));
2372+
assert(kwargs == NULL || PyAnyDict_Check(kwargs));
23732373
if (kwargs != NULL && PyDict_GET_SIZE(kwargs)) {
23742374
PyObject *items = PyDict_Items(kwargs);
23752375
if (items == NULL)

0 commit comments

Comments
 (0)