mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
only catch AttributeError in hasattr() #9666
This commit is contained in:
parent
9cf5ef4cc0
commit
17689991e6
5 changed files with 19 additions and 17 deletions
|
@ -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 *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue