diff --git a/Objects/exceptions.c b/Objects/exceptions.c --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -435,12 +435,13 @@ #define ComplexExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCNEW, \ EXCMETHODS, EXCMEMBERS, EXCGETSET, \ - EXCSTR, EXCDOC) \ + EXCSTR, EXCREPR, EXCDOC) \ static PyTypeObject _PyExc_ ## EXCNAME = { \ PyVarObject_HEAD_INIT(NULL, 0) \ # EXCNAME, \ sizeof(Py ## EXCSTORE ## Object), 0, \ - (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ + (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, \ + (reprfunc)EXCREPR, 0, 0, 0, 0, 0, \ (reprfunc)EXCSTR, 0, 0, 0, \ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \ @@ -525,6 +526,7 @@ StopIteration_members, /* members */ 0, /* getset */ 0, /* str */ + 0, /* repr */ "Signal the end from iterator.__next__()." ); @@ -588,7 +590,7 @@ }; ComplexExtendsException(PyExc_BaseException, SystemExit, SystemExit, - 0, 0, SystemExit_members, 0, 0, + 0, 0, SystemExit_members, 0, 0, 0, "Request to exit from the interpreter."); /* @@ -670,13 +672,20 @@ static PyObject * ImportError_str(PyImportErrorObject *self) { - if (self->msg) { - Py_INCREF(self->msg); - return self->msg; - } - else { - return BaseException_str((PyBaseExceptionObject *)self); - } + if (self->msg || self->name || self->path) + return PyUnicode_FromFormat("%V, %V, %V", self->msg, "", self->name, "", self->path, ""); + return BaseException_str((PyBaseExceptionObject *)self); +} + +static PyObject * +ImportError_repr(PyImportErrorObject *self) +{ + if (self->msg || self->name || self->path) + return PyUnicode_FromFormat("", + self->msg ? self->msg : Py_None, + self->name ? self->name : Py_None, + self->path ? self->path : Py_None); + return BaseException_repr((PyBaseExceptionObject *)self); } static PyMemberDef ImportError_members[] = { @@ -696,7 +705,7 @@ ComplexExtendsException(PyExc_Exception, ImportError, ImportError, 0 /* new */, ImportError_methods, ImportError_members, - 0 /* getset */, ImportError_str, + 0 /* getset */, ImportError_str, ImportError_repr, "Import can't find module, or can't find name in " "module."); @@ -1112,7 +1121,7 @@ ComplexExtendsException(PyExc_Exception, OSError, OSError, OSError_new, OSError_methods, OSError_members, OSError_getset, - OSError_str, + OSError_str, 0, "Base class for I/O related errors."); @@ -1364,7 +1373,7 @@ ComplexExtendsException(PyExc_Exception, SyntaxError, SyntaxError, 0, 0, SyntaxError_members, 0, - SyntaxError_str, "Invalid syntax."); + SyntaxError_str, 0, "Invalid syntax."); /* @@ -1417,7 +1426,7 @@ } ComplexExtendsException(PyExc_LookupError, KeyError, BaseException, - 0, 0, 0, 0, KeyError_str, "Mapping key not found."); + 0, 0, 0, 0, KeyError_str, 0, "Mapping key not found."); /*