summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-09-24 12:50:24 +0000
committerGeorg Brandl <georg@python.org>2006-09-24 12:50:24 +0000
commitc7986cee76cf2ffd6f8351fa8a65ce658825f70a (patch)
treeb452376236b5c4464478e85c707445160a19fc38
parenta10d3afed2f27504768dffd3a915a7c876258505 (diff)
downloadcpython-git-c7986cee76cf2ffd6f8351fa8a65ce658825f70a.tar.gz
Fix a bug in traceback.format_exception_only() that led to an error
being raised when print_exc() was called without an exception set. In version 2.4, this printed "None", restored that behavior.
-rw-r--r--Lib/test/test_traceback.py4
-rw-r--r--Lib/traceback.py2
-rw-r--r--Misc/NEWS4
3 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index b3c5a50958..b42dbc4df4 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -149,6 +149,10 @@ def test():
str_value = '<unprintable %s object>' % X.__name__
self.assertEqual(err[0], X.__name__ + ': ' + str_value + '\n')
+ def test_without_exception(self):
+ err = traceback.format_exception_only(None, None)
+ self.assertEqual(err, ['None\n'])
+
def test_main():
run_unittest(TracebackCases)
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 75e1fcffa3..31b8255379 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -170,7 +170,7 @@ def format_exception_only(etype, value):
# would throw another exception and mask the original problem.
if (isinstance(etype, BaseException) or
isinstance(etype, types.InstanceType) or
- type(etype) is str):
+ etype is None or type(etype) is str):
return [_format_final_exc_line(etype, value)]
stype = etype.__name__
diff --git a/Misc/NEWS b/Misc/NEWS
index ae14e8ffd9..c1a3a6cc3c 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -56,6 +56,10 @@ Core and builtins
Library
-------
+- Fix a bug in traceback.format_exception_only() that led to an error
+ being raised when print_exc() was called without an exception set.
+ In version 2.4, this printed "None", restored that behavior.
+
- Make webbrowser.BackgroundBrowser usable in Windows (it wasn't because
the close_fds arg to subprocess.Popen is not supported).