diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-01-25 08:49:40 (GMT) |
---|---|---|
committer | INADA Naoki <methane@users.noreply.github.com> | 2018-01-25 08:49:40 (GMT) |
commit | f320be77ffb73e3b9e7fc98c37b8df3975d84b40 (patch) | |
tree | 552338f0200938249233fa4aa7b00add61965337 /Objects/dictobject.c | |
parent | 2b822a0bb1de2612c85d8f75e3ce89eda2ac9f68 (diff) | |
download | cpython-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.zip cpython-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.tar.gz cpython-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.tar.bz2 |
bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code (GH-5222)
Add two new private APIs: _PyObject_LookupAttr() and _PyObject_LookupAttrId()
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 259fa25..0d25739 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2234,17 +2234,16 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, } else if (arg != NULL) { _Py_IDENTIFIER(keys); - PyObject *func = _PyObject_GetAttrId(arg, &PyId_keys); - if (func != NULL) { + PyObject *func; + if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) { + result = -1; + } + else if (func != NULL) { Py_DECREF(func); result = PyDict_Merge(self, arg, 1); } - else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - result = PyDict_MergeFromSeq2(self, arg, 1); - } else { - result = -1; + result = PyDict_MergeFromSeq2(self, arg, 1); } } |