Merged revisions 77045 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77045 | ezio.melotti | 2009-12-25 00:25:17 +0200 (Fri, 25 Dec 2009) | 1 line
#6108: unicode(exception) and str(exception) should return the same message
........
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 0a52820..4f18802 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -123,6 +123,21 @@
{
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("");