mirror of
https://github.com/python/cpython.git
synced 2025-08-28 20:56:54 +00:00
Issue #27576: Fix call order in OrderedDict.__init__().
This commit is contained in:
parent
7d895ac953
commit
06aed90a1f
3 changed files with 30 additions and 2 deletions
|
@ -2356,8 +2356,7 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
|
|||
PyObject *other = PyTuple_GET_ITEM(args, 0); /* borrowed reference */
|
||||
assert(other != NULL);
|
||||
Py_INCREF(other);
|
||||
if (PyDict_CheckExact(other) ||
|
||||
_PyObject_HasAttrId(other, &PyId_items)) { /* never fails */
|
||||
if PyDict_CheckExact(other) {
|
||||
PyObject *items;
|
||||
if (PyDict_CheckExact(other))
|
||||
items = PyDict_Items(other);
|
||||
|
@ -2400,6 +2399,20 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
|
|||
if (res != 0 || PyErr_Occurred())
|
||||
return NULL;
|
||||
}
|
||||
else if (_PyObject_HasAttrId(other, &PyId_items)) { /* never fails */
|
||||
PyObject *items;
|
||||
if (PyDict_CheckExact(other))
|
||||
items = PyDict_Items(other);
|
||||
else
|
||||
items = _PyObject_CallMethodId(other, &PyId_items, NULL);
|
||||
Py_DECREF(other);
|
||||
if (items == NULL)
|
||||
return NULL;
|
||||
res = mutablemapping_add_pairs(self, items);
|
||||
Py_DECREF(items);
|
||||
if (res == -1)
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
res = mutablemapping_add_pairs(self, other);
|
||||
Py_DECREF(other);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue