summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2009-12-24 22:32:25 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2009-12-24 22:32:25 (GMT)
commite748238a4f84bf8e4d48233a9dd8377ad0ac3a3e (patch)
treed31e8bd703ee684fb4b397a46879f00600256a7c /Objects/exceptions.c
parent995d6a31e941a63d7bf9538f275d605a85734f98 (diff)
downloadcpython-e748238a4f84bf8e4d48233a9dd8377ad0ac3a3e.zip
cpython-e748238a4f84bf8e4d48233a9dd8377ad0ac3a3e.tar.gz
cpython-e748238a4f84bf8e4d48233a9dd8377ad0ac3a3e.tar.bz2
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 ........
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 0a52820..4f18802 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -123,6 +123,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("");