summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2006-09-09 07:18:44 (GMT)
committerBrett Cannon <bcannon@gmail.com>2006-09-09 07:18:44 (GMT)
commit19d76c5aa88d8f673bc91529d25806d2e333aa84 (patch)
tree8a595553ad00b72b67c01480d2445685824e3cd2
parentb3304c129fac61350a49bdcce73bf1d36ed8d669 (diff)
downloadcpython-19d76c5aa88d8f673bc91529d25806d2e333aa84.zip
cpython-19d76c5aa88d8f673bc91529d25806d2e333aa84.tar.gz
cpython-19d76c5aa88d8f673bc91529d25806d2e333aa84.tar.bz2
Remove __unicode__ method so that ``unicode(BaseException)`` succeeds.
Fixes bug #1551432.
-rw-r--r--Lib/test/test_exceptions.py9
-rw-r--r--Lib/test/test_pep352.py3
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/exceptions.c17
4 files changed, 13 insertions, 19 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index af07aa8..27d88a0 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -304,6 +304,15 @@ class ExceptionTests(unittest.TestCase):
return -1
self.assertRaises(RuntimeError, g)
+ def testUnicodeStrUsage(self):
+ # Make sure both instances and classes have a str and unicode
+ # representation.
+ self.failUnless(str(Exception))
+ self.failUnless(unicode(Exception))
+ self.failUnless(str(Exception('a')))
+ self.failUnless(unicode(Exception(u'a')))
+
+
def test_main():
run_unittest(ExceptionTests)
diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py
index 251e0be..b2322b0 100644
--- a/Lib/test/test_pep352.py
+++ b/Lib/test/test_pep352.py
@@ -15,8 +15,7 @@ class ExceptionClassTests(unittest.TestCase):
self.failUnless(issubclass(Exception, object))
def verify_instance_interface(self, ins):
- for attr in ("args", "message", "__str__", "__unicode__", "__repr__",
- "__getitem__"):
+ for attr in ("args", "message", "__str__", "__repr__", "__getitem__"):
self.failUnless(hasattr(ins, attr), "%s missing %s attribute" %
(ins.__class__.__name__, attr))
diff --git a/Misc/NEWS b/Misc/NEWS
index b72e758..390ad73 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,9 @@ What's New in Python 2.5 release candidate 2?
Core and builtins
-----------------
+- Bug #1551432: Exceptions do not define an explicit __unicode__ method. This
+ allows calling unicode() on exceptions classes directly to succeed.
+
- Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Also make sure that every exception class has __module__ set to
'exceptions'.
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index cdf2609..fda2ab1 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -175,27 +175,10 @@ BaseException_setstate(PyObject *self, PyObject *state)
Py_RETURN_NONE;
}
-#ifdef Py_USING_UNICODE
-/* while this method generates fairly uninspired output, it a least
- * guarantees that we can display exceptions that have unicode attributes
- */
-static PyObject *
-BaseException_unicode(PyBaseExceptionObject *self)
-{
- if (PyTuple_GET_SIZE(self->args) == 0)
- return PyUnicode_FromUnicode(NULL, 0);
- if (PyTuple_GET_SIZE(self->args) == 1)
- return PyObject_Unicode(PyTuple_GET_ITEM(self->args, 0));
- return PyObject_Unicode(self->args);
-}
-#endif /* Py_USING_UNICODE */
static PyMethodDef BaseException_methods[] = {
{"__reduce__", (PyCFunction)BaseException_reduce, METH_NOARGS },
{"__setstate__", (PyCFunction)BaseException_setstate, METH_O },
-#ifdef Py_USING_UNICODE
- {"__unicode__", (PyCFunction)BaseException_unicode, METH_NOARGS },
-#endif
{NULL, NULL, 0, NULL},
};