From c823d7b0054a8fb42efa9c950169ffc0431d8378 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Tue, 3 Nov 2026 00:56:37 -0800 Subject: [PATCH] [mypyc] use PyObject_GetOptionalAttr in GetAttr3 This should be faster --- mypyc/lib-rt/generic_ops.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mypyc/lib-rt/generic_ops.c b/mypyc/lib-rt/generic_ops.c index 58312033f4db1..09e6df362343a 100644 --- a/mypyc/lib-rt/generic_ops.c +++ b/mypyc/lib-rt/generic_ops.c @@ -22,11 +22,9 @@ CPyTagged CPyObject_Hash(PyObject *o) { PyObject *CPyObject_GetAttr3(PyObject *v, PyObject *name, PyObject *defl) { - PyObject *result = PyObject_GetAttr(v, name); - if (!result && PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - Py_INCREF(defl); - result = defl; + PyObject *result; + if (PyObject_GetOptionalAttr(v, name, &result) == 0) { + return Py_NewRef(defl); } return result; }