summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2009-12-24 22:25:17 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2009-12-24 22:25:17 (GMT)
commitf84caf4edae9d1357db6afec75b042caf54cf3f5 (patch)
tree967c31d1ac2e16935d07036e560f744de51d5f7f /Objects/exceptions.c
parentdb69f01ea909ccd5209f0e2cd532263760f67ce7 (diff)
downloadcpython-f84caf4edae9d1357db6afec75b042caf54cf3f5.zip
cpython-f84caf4edae9d1357db6afec75b042caf54cf3f5.tar.gz
cpython-f84caf4edae9d1357db6afec75b042caf54cf3f5.tar.bz2
#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 0a39a6b..c246d67 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("");