From: Guido van Rossum Date: Tue, 16 Oct 2001 21:31:32 +0000 (+0000) Subject: SF patch #471852 (anonymous) notes that getattr(obj, name, default) X-Git-Tag: v2.2.1c1~1243 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d892357bf7bfb8ce34a0652c7002d78bbce17b6e;p=python SF patch #471852 (anonymous) notes that getattr(obj, name, default) masks any exception, not just AttributeError. Fix this. --- 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;