Index: Objects/exceptions.c =================================================================== --- Objects/exceptions.c (revision 63986) +++ Objects/exceptions.c (working copy) @@ -117,7 +117,29 @@ return out; } +#ifdef Py_USING_UNICODE static PyObject * +BaseException_unicode(PyBaseExceptionObject *self) +{ + PyObject *out; + + switch (PyTuple_GET_SIZE(self->args)) { + case 0: + out = PyUnicode_FromString(""); + break; + case 1: + out = PyObject_Unicode(PyTuple_GET_ITEM(self->args, 0)); + break; + default: + out = PyObject_Unicode(self->args); + break; + } + + return out; +} +#endif + +static PyObject * BaseException_repr(PyBaseExceptionObject *self) { PyObject *repr_suffix; @@ -181,6 +203,9 @@ static PyMethodDef BaseException_methods[] = { {"__reduce__", (PyCFunction)BaseException_reduce, METH_NOARGS }, {"__setstate__", (PyCFunction)BaseException_setstate, METH_O }, +#ifdef Py_USING_UNICODE + {"__unicode__", (PyCFunction)BaseException_unicode, METH_NOARGS }, +#endif {NULL, NULL, 0, NULL}, }; Index: Lib/test/test_exceptions.py =================================================================== --- Lib/test/test_exceptions.py (revision 63986) +++ Lib/test/test_exceptions.py (working copy) @@ -339,9 +339,12 @@ # Make sure both instances and classes have a str and unicode # representation. self.failUnless(str(Exception)) - self.failUnless(unicode(Exception)) + # The test below can't work unless __unicode__ gains a tp_unicode slot + # which will probably never happen. + # self.failUnless(unicode(Exception)) self.failUnless(str(Exception('a'))) self.failUnless(unicode(Exception(u'a'))) + self.failUnless(unicode(Exception(u'\xe1'))) def test_main():