@@ -1864,6 +1864,30 @@ ImportError_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
18641864 return res ;
18651865}
18661866
1867+ static PyObject *
1868+ ImportError_repr (PyImportErrorObject * self )
1869+ {
1870+ int hasargs = PyTuple_GET_SIZE (((PyBaseExceptionObject * )self )-> args ) != 0 ;
1871+ PyObject * r = BaseException_repr ((PyBaseExceptionObject * )self );
1872+ if (r && (self -> name || self -> path )) {
1873+ /* remove ')' */
1874+ Py_SETREF (r , PyUnicode_Substring (r , 0 , PyUnicode_GET_LENGTH (r ) - 1 ));
1875+ if (r && self -> name ) {
1876+ Py_SETREF (r , PyUnicode_FromFormat ("%U%sname=%R" ,
1877+ r , hasargs ? ", " : "" , self -> name ));
1878+ hasargs = 1 ;
1879+ }
1880+ if (r && self -> path ) {
1881+ Py_SETREF (r , PyUnicode_FromFormat ("%U%spath=%R" ,
1882+ r , hasargs ? ", " : "" , self -> path ));
1883+ }
1884+ if (r ) {
1885+ Py_SETREF (r , PyUnicode_FromFormat ("%U)" , r ));
1886+ }
1887+ }
1888+ return r ;
1889+ }
1890+
18671891static PyMemberDef ImportError_members [] = {
18681892 {"msg" , _Py_T_OBJECT , offsetof(PyImportErrorObject , msg ), 0 ,
18691893 PyDoc_STR ("exception message" )},
@@ -1881,12 +1905,23 @@ static PyMethodDef ImportError_methods[] = {
18811905 {NULL }
18821906};
18831907
1884- ComplexExtendsException (PyExc_Exception , ImportError ,
1885- ImportError , 0 /* new */ ,
1886- ImportError_methods , ImportError_members ,
1887- 0 /* getset */ , ImportError_str ,
1888- "Import can't find module, or can't find name in "
1889- "module." );
1908+ static PyTypeObject _PyExc_ImportError = {
1909+ PyVarObject_HEAD_INIT (NULL , 0 )
1910+ "ImportError" ,
1911+ sizeof (PyImportErrorObject ), 0 ,
1912+ (destructor )ImportError_dealloc , 0 , 0 , 0 , 0 ,
1913+ (reprfunc )ImportError_repr , 0 , 0 , 0 , 0 , 0 ,
1914+ (reprfunc )ImportError_str , 0 , 0 , 0 ,
1915+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC ,
1916+ PyDoc_STR ("Import can't find module, or can't find name in "
1917+ "module." ),
1918+ (traverseproc )ImportError_traverse ,
1919+ (inquiry )ImportError_clear , 0 , 0 , 0 , 0 , ImportError_methods ,
1920+ ImportError_members , 0 , & _PyExc_Exception ,
1921+ 0 , 0 , 0 , offsetof(PyImportErrorObject , dict ),
1922+ (initproc )ImportError_init ,
1923+ };
1924+ PyObject * PyExc_ImportError = (PyObject * )& _PyExc_ImportError ;
18901925
18911926/*
18921927 * ModuleNotFoundError extends ImportError
0 commit comments