mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
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:
parent
2b822a0bb1
commit
f320be77ff
22 changed files with 1455 additions and 1442 deletions
|
@ -80,11 +80,8 @@ get_warnings_attr(_Py_Identifier *attr_id, int try_import)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
obj = _PyObject_GetAttrId(warnings_module, attr_id);
|
||||
(void)_PyObject_LookupAttrId(warnings_module, attr_id, &obj);
|
||||
Py_DECREF(warnings_module);
|
||||
if (obj == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -893,13 +890,10 @@ get_source_line(PyObject *module_globals, int lineno)
|
|||
Py_INCREF(module_name);
|
||||
|
||||
/* Make sure the loader implements the optional get_source() method. */
|
||||
get_source = _PyObject_GetAttrId(loader, &PyId_get_source);
|
||||
(void)_PyObject_LookupAttrId(loader, &PyId_get_source, &get_source);
|
||||
Py_DECREF(loader);
|
||||
if (!get_source) {
|
||||
Py_DECREF(module_name);
|
||||
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/* Call get_source() to get the source code. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue