diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2017-11-11 14:19:56 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-11 14:19:56 (GMT) |
| commit | 60c3d3551a96febac7b6016fb44605643842c686 (patch) | |
| tree | 5c676b97f4ef58958a3042d143eddb38325b7008 /Objects/dictobject.c | |
| parent | 1707e4020fa8dca8e6a3ac4f9da105b54d597b66 (diff) | |
| download | cpython-60c3d3551a96febac7b6016fb44605643842c686.zip cpython-60c3d3551a96febac7b6016fb44605643842c686.tar.gz cpython-60c3d3551a96febac7b6016fb44605643842c686.tar.bz2 | |
bpo-31572: Get rid of _PyObject_HasAttrId() in dict and OrderedDict. (#3728)
Silence only AttributeError when get "key" and "items" attributes in
the constructor and the update() method of dict and OrderedDict .
Diffstat (limited to 'Objects/dictobject.c')
| -rw-r--r-- | Objects/dictobject.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 779746a..b20b85c 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2183,16 +2183,25 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, PyObject *arg = NULL; int result = 0; - if (!PyArg_UnpackTuple(args, methname, 0, 1, &arg)) + if (!PyArg_UnpackTuple(args, methname, 0, 1, &arg)) { result = -1; - + } else if (arg != NULL) { _Py_IDENTIFIER(keys); - if (_PyObject_HasAttrId(arg, &PyId_keys)) + PyObject *func = _PyObject_GetAttrId(arg, &PyId_keys); + if (func != NULL) { + Py_DECREF(func); result = PyDict_Merge(self, arg, 1); - else + } + else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); result = PyDict_MergeFromSeq2(self, arg, 1); + } + else { + result = -1; + } } + if (result == 0 && kwds != NULL) { if (PyArg_ValidateKeywordArguments(kwds)) result = PyDict_Merge(self, kwds, 1); |
