summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-08-04 04:50:21 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-08-04 04:50:21 (GMT)
commitff4b63b80f36fdeac1338f32ec2c4eb689b78e49 (patch)
tree3a44c046e02bf8a9f08aa68b45b943aaf5d5e345
parent4b8bd31ef0d77990caa11a58938dae9f52b65ebd (diff)
downloadcpython-ff4b63b80f36fdeac1338f32ec2c4eb689b78e49.zip
cpython-ff4b63b80f36fdeac1338f32ec2c4eb689b78e49.tar.gz
cpython-ff4b63b80f36fdeac1338f32ec2c4eb689b78e49.tar.bz2
Bug #1531405, format_exception no longer raises an exception if
str(exception) raised an exception.
-rw-r--r--Lib/test/test_traceback.py17
-rw-r--r--Lib/traceback.py7
-rw-r--r--Misc/NEWS32
3 files changed, 51 insertions, 5 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 7f0ede5..b3c5a50 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -130,15 +130,24 @@ def test():
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():
diff --git a/Lib/traceback.py b/Lib/traceback.py
index a0b5759..505a305 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -202,7 +202,12 @@ def format_exception_only(etype, value):
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))
diff --git a/Misc/NEWS b/Misc/NEWS
index 1923b4f..7a1d7bf 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -4,6 +4,38 @@ Python News
(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?
================================