From 17689991e6ef5831eae57b2e91f178256d6d3ccb Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 24 Aug 2010 03:26:23 +0000 Subject: only catch AttributeError in hasattr() #9666 --- Python/bltinmodule.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index e1f2931dbc..3bcb08ee98 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -893,24 +893,21 @@ builtin_hasattr(PyObject *self, PyObject *args) } v = PyObject_GetAttr(v, name); if (v == NULL) { - if (!PyErr_ExceptionMatches(PyExc_Exception)) - return NULL; - else { + if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); - Py_INCREF(Py_False); - return Py_False; + Py_RETURN_FALSE; } + return NULL; } Py_DECREF(v); - Py_INCREF(Py_True); - return Py_True; + Py_RETURN_TRUE; } PyDoc_STRVAR(hasattr_doc, "hasattr(object, name) -> bool\n\ \n\ Return whether the object has an attribute with the given name.\n\ -(This is done by calling getattr(object, name) and catching exceptions.)"); +(This is done by calling getattr(object, name) and catching AttributeError.)"); static PyObject * -- cgit v1.2.1