[Python-checkins] r51838 - in python/branches/release25-maint: Lib/test/test_exceptions.py Lib/test/test_pep352.py Misc/NEWS Objects/exceptions.c

brett.cannon python-checkins at python.org
Sat Sep 9 09:18:45 CEST 2006


Author: brett.cannon
Date: Sat Sep  9 09:18:44 2006
New Revision: 51838

Modified:
   python/branches/release25-maint/Lib/test/test_exceptions.py
   python/branches/release25-maint/Lib/test/test_pep352.py
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Objects/exceptions.c
Log:
Remove __unicode__ method so that ``unicode(BaseException)`` succeeds.

Fixes bug #1551432.


Modified: python/branches/release25-maint/Lib/test/test_exceptions.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_exceptions.py	(original)
+++ python/branches/release25-maint/Lib/test/test_exceptions.py	Sat Sep  9 09:18:44 2006
@@ -304,6 +304,15 @@
                 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)
 

Modified: python/branches/release25-maint/Lib/test/test_pep352.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_pep352.py	(original)
+++ python/branches/release25-maint/Lib/test/test_pep352.py	Sat Sep  9 09:18:44 2006
@@ -15,8 +15,7 @@
         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))
 

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Sat Sep  9 09:18:44 2006
@@ -19,6 +19,9 @@
 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'.

Modified: python/branches/release25-maint/Objects/exceptions.c
==============================================================================
--- python/branches/release25-maint/Objects/exceptions.c	(original)
+++ python/branches/release25-maint/Objects/exceptions.c	Sat Sep  9 09:18:44 2006
@@ -175,27 +175,10 @@
     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},
 };
 


More information about the Python-checkins mailing list