gh-102213: Revert "gh-102213: Optimize the performance of __getattr__ (GH-102248)" (GH-103332)

This reverts commit aa0a73d1bc.
This commit is contained in:
Nikita Sobolev 2023-04-07 12:22:36 +03:00 committed by GitHub
parent efb0a2cf3a
commit 059bb04245
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 13 deletions

View file

@ -375,7 +375,6 @@ extern void _PyObject_FreeInstanceAttributes(PyObject *obj);
extern int _PyObject_IsInstanceDictEmpty(PyObject *); extern int _PyObject_IsInstanceDictEmpty(PyObject *);
extern int _PyType_HasSubclasses(PyTypeObject *); extern int _PyType_HasSubclasses(PyTypeObject *);
extern PyObject* _PyType_GetSubclasses(PyTypeObject *); extern PyObject* _PyType_GetSubclasses(PyTypeObject *);
extern PyObject* _PyObject_GenericTryGetAttr(PyObject *, PyObject *);
// Access macro to the members which are floating "behind" the object // Access macro to the members which are floating "behind" the object
static inline PyMemberDef* _PyHeapType_GET_MEMBERS(PyHeapTypeObject *etype) { static inline PyMemberDef* _PyHeapType_GET_MEMBERS(PyHeapTypeObject *etype) {

View file

@ -1491,12 +1491,6 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
return _PyObject_GenericGetAttrWithDict(obj, name, NULL, 0); return _PyObject_GenericGetAttrWithDict(obj, name, NULL, 0);
} }
PyObject *
_PyObject_GenericTryGetAttr(PyObject *obj, PyObject *name)
{
return _PyObject_GenericGetAttrWithDict(obj, name, NULL, 1);
}
int int
_PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name, _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
PyObject *value, PyObject *dict) PyObject *value, PyObject *dict)

View file

@ -8274,17 +8274,14 @@ _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name)
(Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) && (Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) &&
((PyWrapperDescrObject *)getattribute)->d_wrapped == ((PyWrapperDescrObject *)getattribute)->d_wrapped ==
(void *)PyObject_GenericGetAttr)) (void *)PyObject_GenericGetAttr))
/* finding nothing is reasonable when __getattr__ is defined */ res = PyObject_GenericGetAttr(self, name);
res = _PyObject_GenericTryGetAttr(self, name);
else { else {
Py_INCREF(getattribute); Py_INCREF(getattribute);
res = call_attribute(self, getattribute, name); res = call_attribute(self, getattribute, name);
Py_DECREF(getattribute); Py_DECREF(getattribute);
} }
if (res == NULL) { if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear(); PyErr_Clear();
}
res = call_attribute(self, getattr, name); res = call_attribute(self, getattr, name);
} }
Py_DECREF(getattr); Py_DECREF(getattr);