Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 64259:2de9d4457082
only catch AttributeError in hasattr() #9666
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Tue, 24 Aug 2010 03:26:23 +0000 |
| parents | 846866aa0eb6 |
| children | 999d7d212f17 |
line wrap: on
line diff
--- a/Python/bltinmodule.c Mon Aug 23 22:28:13 2010 +0000 +++ b/Python/bltinmodule.c Tue Aug 24 03:26:23 2010 +0000 @@ -893,24 +893,21 @@ } 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 *
