[Python-checkins] gh-102213: Revert "gh-102213: Optimize the performance of `__getattr__` (GH-102248)" (GH-103332)
Fidget-Spinner
webhook-mailer at python.org
Fri Apr 7 05:23:17 EDT 2023
https://github.com/python/cpython/commit/059bb04245a8b3490f93dfd72522a431a113eef1
commit: 059bb04245a8b3490f93dfd72522a431a113eef1
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: Fidget-Spinner <kenjin at python.org>
date: 2023-04-07T17:22:36+08:00
summary:
gh-102213: Revert "gh-102213: Optimize the performance of `__getattr__` (GH-102248)" (GH-103332)
This reverts commit aa0a73d1bc53dcb6348a869df1e775138991e561.
files:
M Include/internal/pycore_object.h
M Objects/object.c
M Objects/typeobject.c
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index e18e787449c2..b3d496ed6fc2 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -375,7 +375,6 @@ extern void _PyObject_FreeInstanceAttributes(PyObject *obj);
extern int _PyObject_IsInstanceDictEmpty(PyObject *);
extern int _PyType_HasSubclasses(PyTypeObject *);
extern PyObject* _PyType_GetSubclasses(PyTypeObject *);
-extern PyObject* _PyObject_GenericTryGetAttr(PyObject *, PyObject *);
// Access macro to the members which are floating "behind" the object
static inline PyMemberDef* _PyHeapType_GET_MEMBERS(PyHeapTypeObject *etype) {
diff --git a/Objects/object.c b/Objects/object.c
index 9dd5eb998217..71f098eed37f 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1491,12 +1491,6 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
return _PyObject_GenericGetAttrWithDict(obj, name, NULL, 0);
}
-PyObject *
-_PyObject_GenericTryGetAttr(PyObject *obj, PyObject *name)
-{
- return _PyObject_GenericGetAttrWithDict(obj, name, NULL, 1);
-}
-
int
_PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
PyObject *value, PyObject *dict)
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 24541bddbbc3..995547e7915f 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -8274,17 +8274,14 @@ _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name)
(Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) &&
((PyWrapperDescrObject *)getattribute)->d_wrapped ==
(void *)PyObject_GenericGetAttr))
- /* finding nothing is reasonable when __getattr__ is defined */
- res = _PyObject_GenericTryGetAttr(self, name);
+ res = PyObject_GenericGetAttr(self, name);
else {
Py_INCREF(getattribute);
res = call_attribute(self, getattribute, name);
Py_DECREF(getattribute);
}
- if (res == NULL) {
- if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
- PyErr_Clear();
- }
+ if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ PyErr_Clear();
res = call_attribute(self, getattr, name);
}
Py_DECREF(getattr);
More information about the Python-checkins
mailing list