mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +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
|
|
@ -1073,12 +1073,10 @@ fileio_repr(fileio *self)
|
|||
if (self->fd < 0)
|
||||
return PyUnicode_FromFormat("<_io.FileIO [closed]>");
|
||||
|
||||
nameobj = _PyObject_GetAttrId((PyObject *) self, &PyId_name);
|
||||
if (_PyObject_LookupAttrId((PyObject *) self, &PyId_name, &nameobj) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (nameobj == NULL) {
|
||||
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||
PyErr_Clear();
|
||||
else
|
||||
return NULL;
|
||||
res = PyUnicode_FromFormat(
|
||||
"<_io.FileIO fd=%d mode='%s' closefd=%s>",
|
||||
self->fd, mode_string(self), self->closefd ? "True" : "False");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue