[3.8] bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630) (GH-15635)
Only AttributeError should be silenced.
(cherry picked from commit 41c57b335330ff48af098d47e379e0f9ba09d233)
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 014cbb4..46d4143 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -1382,7 +1382,10 @@
Py_DECREF(self);
return NULL;
}
- self->write = _PyObject_GetAttrId(output_file, &PyId_write);
+ if (_PyObject_LookupAttrId(output_file, &PyId_write, &self->write) < 0) {
+ Py_DECREF(self);
+ return NULL;
+ }
if (self->write == NULL || !PyCallable_Check(self->write)) {
PyErr_SetString(PyExc_TypeError,
"argument 1 must have a \"write\" method");