bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code (GH-5222)

Add two new private APIs: _PyObject_LookupAttr() and _PyObject_LookupAttrId()
This commit is contained in:
Serhiy Storchaka 2018-01-25 10:49:40 +02:00 committed by INADA Naoki
parent 2b822a0bb1
commit f320be77ff
22 changed files with 1455 additions and 1442 deletions

View file

@ -830,17 +830,15 @@ tee(PyObject *self, PyObject *args)
return NULL;
}
copyfunc = _PyObject_GetAttrId(it, &PyId___copy__);
if (copyfunc != NULL) {
copyable = it;
}
else if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
if (_PyObject_LookupAttrId(it, &PyId___copy__, &copyfunc) < 0) {
Py_DECREF(it);
Py_DECREF(result);
return NULL;
}
if (copyfunc != NULL) {
copyable = it;
}
else {
PyErr_Clear();
copyable = tee_fromiterable(it);
Py_DECREF(it);
if (copyable == NULL) {