summaryrefslogtreecommitdiff
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 0a39a6bee9..c246d67dbe 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -122,6 +122,21 @@ BaseException_unicode(PyBaseExceptionObject *self)
{
PyObject *out;
+ /* issue6108: if __str__ has been overridden in the subclass, unicode()
+ should return the message returned by __str__ as used to happen
+ before this method was implemented. */
+ if (Py_TYPE(self)->tp_str != (reprfunc)BaseException_str) {
+ PyObject *str;
+ /* Unlike PyObject_Str, tp_str can return unicode (i.e. return the
+ equivalent of unicode(e.__str__()) instead of unicode(str(e))). */
+ str = Py_TYPE(self)->tp_str((PyObject*)self);
+ if (str == NULL)
+ return NULL;
+ out = PyObject_Unicode(str);
+ Py_DECREF(str);
+ return out;
+ }
+
switch (PyTuple_GET_SIZE(self->args)) {
case 0:
out = PyUnicode_FromString("");