diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2016-09-09 18:59:08 (GMT) |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2016-09-09 18:59:08 (GMT) |
commit | 06aed90a1fe6fa48919ff0f1f39181e886df9efc (patch) | |
tree | 15ce099cf743bc12cf80bf2a5bfe9d04834b9058 /Objects/odictobject.c | |
parent | 7d895ac953d2ba8c6cb9ade995aef131ddc77ab2 (diff) | |
download | cpython-06aed90a1fe6fa48919ff0f1f39181e886df9efc.zip cpython-06aed90a1fe6fa48919ff0f1f39181e886df9efc.tar.gz cpython-06aed90a1fe6fa48919ff0f1f39181e886df9efc.tar.bz2 |
Issue #27576: Fix call order in OrderedDict.__init__().
Diffstat (limited to 'Objects/odictobject.c')
-rw-r--r-- | Objects/odictobject.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 5968e3f..22b1f1d 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -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); |