From 1e25d8477f635b4b5cbfa49847865496379c736e Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 11 Feb 2024 06:35:53 +0300 Subject: [PATCH] use PyObject_GetAttr & ignore exceptions --- Objects/descrobject.c | 3 +-- Objects/typeobject.c | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 1131cd3fa928a1..571948229054d0 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -130,8 +130,7 @@ classmethod_get(PyObject *self, PyObject *obj, PyObject *type) if (descr->d_method->ml_flags & METH_METHOD) { cls = descr->d_common.d_type; } - PyObject *mod; - PyObject_GetOptionalAttr((PyObject*)type, &_Py_ID(__module__), &mod); + PyObject *mod = PyObject_GetAttr((PyObject*)type, &_Py_ID(__module__)); PyErr_Clear(); PyObject *result = PyCMethod_New(descr->d_method, type, mod, cls); Py_XDECREF(mod); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index c01c48ec107982..fcd54a2b040e9d 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6653,8 +6653,8 @@ type_add_method(PyTypeObject *type, PyMethodDef *meth) descr = PyDescr_NewClassMethod(type, meth); } else if (meth->ml_flags & METH_STATIC) { - PyObject *mod; - PyObject_GetOptionalAttr((PyObject*)type, &_Py_ID(__module__), &mod); + PyObject *mod = PyObject_GetAttr((PyObject*)type, &_Py_ID(__module__)); + PyErr_Clear(); PyObject *cfunc = PyCFunction_NewEx(meth, (PyObject*)type, mod); Py_XDECREF(mod); if (cfunc == NULL) {