diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-08-24 03:26:23 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-08-24 03:26:23 (GMT) |
commit | 17689991e6ef5831eae57b2e91f178256d6d3ccb (patch) | |
tree | 21a954c86d8f461ecc06d8c6de8880429c6e97ec /Python/bltinmodule.c | |
parent | 9cf5ef4cc0015848ef831db31b19c77e6a4273e0 (diff) | |
download | cpython-17689991e6ef5831eae57b2e91f178256d6d3ccb.zip cpython-17689991e6ef5831eae57b2e91f178256d6d3ccb.tar.gz cpython-17689991e6ef5831eae57b2e91f178256d6d3ccb.tar.bz2 |
only catch AttributeError in hasattr() #9666
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index e1f2931..3bcb08e 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 * |