@@ -2702,6 +2702,23 @@ AttributeError_dealloc(PyObject *self)
27022702 Py_TYPE (self )-> tp_free (self );
27032703}
27042704
2705+ static PyObject *
2706+ AttributeError_str (PyObject * op )
2707+ {
2708+ PyAttributeErrorObject * self = PyAttributeErrorObject_CAST (op );
2709+ if (
2710+ self -> obj
2711+ && (!PyTuple_GET_SIZE (self -> args )
2712+ || (PyTuple_GET_SIZE (self -> args ) == 1
2713+ && PyUnicode_Equal (PyTuple_GET_ITEM (self -> args , 0 ), self -> name ))
2714+ )
2715+ ) {
2716+ return PyUnicode_FromFormat ("%R has no attribute '%U'" ,
2717+ self -> obj , self -> name );
2718+ }
2719+ return BaseException_str (op );
2720+ }
2721+
27052722static int
27062723AttributeError_traverse (PyObject * op , visitproc visit , void * arg )
27072724{
@@ -2770,7 +2787,7 @@ static PyMethodDef AttributeError_methods[] = {
27702787ComplexExtendsException (PyExc_Exception , AttributeError ,
27712788 AttributeError , 0 ,
27722789 AttributeError_methods , AttributeError_members ,
2773- 0 , BaseException_str , 0 , "Attribute not found." );
2790+ 0 , AttributeError_str , 0 , "Attribute not found." );
27742791
27752792/*
27762793 * SyntaxError extends Exception
0 commit comments