]> granicus.if.org Git - python/commitdiff
Remove the __unicode__ method from exceptions. Allows unicode() to be called
authorBrett Cannon <bcannon@gmail.com>
Sat, 9 Sep 2006 07:11:46 +0000 (07:11 +0000)
committerBrett Cannon <bcannon@gmail.com>
Sat, 9 Sep 2006 07:11:46 +0000 (07:11 +0000)
on exception classes.  Would require introducing a tp_unicode slot to make it
work otherwise.

Fixes bug #1551432 and will be backported.

Lib/test/test_exceptions.py
Lib/test/test_pep352.py
Objects/exceptions.c

index af07aa8aa9268697ba2c0d19d76b4bf124b84e25..27d88a0fd5f079df7180ce05097fde5eaacf10f8 100644 (file)
@@ -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)
 
index 251e0be0a8fb580fa0b6a294a6657c9b04ceb3de..b2322b0a3a784acdb2526da9cbb6860c2fc82c56 100644 (file)
@@ -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))
 
index cdf2609bc8c250b7cc6d5ee39782c2ae95ccbe1b..fda2ab1e301ec82b8f80b1df2eb71eaf3ffd393c 100644 (file)
@@ -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},
 };