mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +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
|
@ -540,15 +540,11 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding,
|
|||
* attribute.
|
||||
*/
|
||||
if (!PyTuple_CheckExact(codec)) {
|
||||
attr = _PyObject_GetAttrId(codec, &PyId__is_text_encoding);
|
||||
if (attr == NULL) {
|
||||
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
PyErr_Clear();
|
||||
} else {
|
||||
Py_DECREF(codec);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (_PyObject_LookupAttrId(codec, &PyId__is_text_encoding, &attr) < 0) {
|
||||
Py_DECREF(codec);
|
||||
return NULL;
|
||||
}
|
||||
if (attr != NULL) {
|
||||
is_text_codec = PyObject_IsTrue(attr);
|
||||
Py_DECREF(attr);
|
||||
if (is_text_codec <= 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue