diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2009-12-24 22:32:25 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2009-12-24 22:32:25 (GMT) |
commit | e748238a4f84bf8e4d48233a9dd8377ad0ac3a3e (patch) | |
tree | d31e8bd703ee684fb4b397a46879f00600256a7c /Objects/exceptions.c | |
parent | 995d6a31e941a63d7bf9538f275d605a85734f98 (diff) | |
download | cpython-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.c | 15 |
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(""); |