Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 48b47b0..c0254ff 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -117,6 +117,28 @@
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)
{
@@ -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},
};