gh-92216: improve performance of hasattr for type objects (GH-99979)

This commit is contained in:
Pieter Eendebak 2022-12-23 16:23:36 +01:00 committed by GitHub
parent 49f6ff719c
commit 7fc7909677
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 8 deletions

View file

@ -939,7 +939,15 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
}
return 0;
}
if (tp->tp_getattro != NULL) {
if (tp->tp_getattro == (getattrofunc)_Py_type_getattro) {
int supress_missing_attribute_exception = 0;
*result = _Py_type_getattro_impl((PyTypeObject*)v, name, &supress_missing_attribute_exception);
if (supress_missing_attribute_exception) {
// return 0 without having to clear the exception
return 0;
}
}
else if (tp->tp_getattro != NULL) {
*result = (*tp->tp_getattro)(v, name);
}
else if (tp->tp_getattr != NULL) {