bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630)
Only AttributeError should be silenced.
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 0faf7e7..61c9428 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -185,8 +185,10 @@
if (PyLong_Check(o)) {
fd = _PyLong_AsInt(o);
}
- else if ((meth = _PyObject_GetAttrId(o, &PyId_fileno)) != NULL)
- {
+ else if (_PyObject_LookupAttrId(o, &PyId_fileno, &meth) < 0) {
+ return -1;
+ }
+ else if (meth != NULL) {
PyObject *fno = _PyObject_CallNoArg(meth);
Py_DECREF(meth);
if (fno == NULL)