From d892357bf7bfb8ce34a0652c7002d78bbce17b6e Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 16 Oct 2001 21:31:32 +0000 Subject: [PATCH] SF patch #471852 (anonymous) notes that getattr(obj, name, default) masks any exception, not just AttributeError. Fix this. --- Python/bltinmodule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 8390b7b80b..144a62f920 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -619,7 +619,9 @@ builtin_getattr(PyObject *self, PyObject *args) return NULL; } result = PyObject_GetAttr(v, name); - if (result == NULL && dflt != NULL) { + if (result == NULL && dflt != NULL && + PyErr_ExceptionMatches(PyExc_AttributeError)) + { PyErr_Clear(); Py_INCREF(dflt); result = dflt; -- 2.50.0