]> granicus.if.org Git - python/commitdiff
Fix a bug in traceback.format_exception_only() that led to an error
authorGeorg Brandl <georg@python.org>
Sun, 24 Sep 2006 12:50:28 +0000 (12:50 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 24 Sep 2006 12:50:28 +0000 (12:50 +0000)
being raised when print_exc() was called without an exception set.
In version 2.4, this printed "None", restored that behavior.
 (backport from rev. 51995)

Lib/test/test_traceback.py
Lib/traceback.py
Misc/NEWS

index b3c5a509580cc874a686a136e4c92c0b73f8821d..b42dbc4df4bb93f5214a9c19447bd6f67e6bd73e 100644 (file)
@@ -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)
index 75e1fcffa382e9f6991819adc1f3b588016c8a20..31b825537989e3a00d2777c31cee3a64455ccbd6 100644 (file)
@@ -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__
index e930453ade5384cf5b3b63ec99fb1f8fcdeb0773..685daf682323dd5988fda03ed3b914403c28e744 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -28,6 +28,10 @@ Extension Modules
 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).