[Python-checkins] r51079 - in python/trunk: Lib/test/test_traceback.py Lib/traceback.py Misc/NEWS

neal.norwitz python-checkins at python.org
Fri Aug 4 06:50:22 CEST 2006


Author: neal.norwitz
Date: Fri Aug  4 06:50:21 2006
New Revision: 51079

Modified:
   python/trunk/Lib/test/test_traceback.py
   python/trunk/Lib/traceback.py
   python/trunk/Misc/NEWS
Log:
Bug #1531405, format_exception no longer raises an exception if
str(exception) raised an exception.


Modified: python/trunk/Lib/test/test_traceback.py
==============================================================================
--- python/trunk/Lib/test/test_traceback.py	(original)
+++ python/trunk/Lib/test/test_traceback.py	Fri Aug  4 06:50:21 2006
@@ -130,15 +130,24 @@
     def test_string_exception1(self):
         str_type = "String Exception"
         err = traceback.format_exception_only(str_type, None)
-        self.assert_(len(err) == 1)
-        self.assert_(err[0] == str_type + '\n')
+        self.assertEqual(len(err), 1)
+        self.assertEqual(err[0], str_type + '\n')
 
     def test_string_exception2(self):
         str_type = "String Exception"
         str_value = "String Value"
         err = traceback.format_exception_only(str_type, str_value)
-        self.assert_(len(err) == 1)
-        self.assert_(err[0] == str_type + ': ' + str_value + '\n')
+        self.assertEqual(len(err), 1)
+        self.assertEqual(err[0], str_type + ': ' + str_value + '\n')
+
+    def test_format_exception_only_bad__str__(self):
+        class X(Exception):
+            def __str__(self):
+                1/0
+        err = traceback.format_exception_only(X, X())
+        self.assertEqual(len(err), 1)
+        str_value = '<unprintable %s object>' % X.__name__
+        self.assertEqual(err[0], X.__name__ + ': ' + str_value + '\n')
 
 
 def test_main():

Modified: python/trunk/Lib/traceback.py
==============================================================================
--- python/trunk/Lib/traceback.py	(original)
+++ python/trunk/Lib/traceback.py	Fri Aug  4 06:50:21 2006
@@ -202,7 +202,12 @@
 
 def _format_final_exc_line(etype, value):
     """Return a list of a single line -- normal case for format_exception_only"""
-    if value is None or not str(value):
+    try:
+        printable = value is None or not str(value)
+    except:
+        printable = False
+
+    if printable:
         line = "%s\n" % etype
     else:
         line = "%s: %s\n" % (etype, _some_str(value))

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Aug  4 06:50:21 2006
@@ -4,6 +4,38 @@
 
 (editors: check NEWS.help for information about editing NEWS using ReST.)
 
+What's New in Python 2.5 release candidate 1?
+=============================================
+
+*Release date: XX-AUG-2006*
+
+Core and builtins
+-----------------
+
+
+Library
+-------
+
+- Bug #1531405, format_exception no longer raises an exception if
+  str(exception) raised an exception.
+
+
+Extension Modules
+-----------------
+
+
+Tests
+-----
+
+
+Build
+-----
+
+
+Mac
+---
+
+
 What's New in Python 2.5 beta 3?
 ================================
 


More information about the Python-checkins mailing list