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

georg.brandl python-checkins at python.org
Sun Sep 24 14:50:26 CEST 2006


Author: georg.brandl
Date: Sun Sep 24 14:50:24 2006
New Revision: 51995

Modified:
   python/trunk/Lib/test/test_traceback.py
   python/trunk/Lib/traceback.py
   python/trunk/Misc/NEWS
Log:
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.


Modified: python/trunk/Lib/test/test_traceback.py
==============================================================================
--- python/trunk/Lib/test/test_traceback.py	(original)
+++ python/trunk/Lib/test/test_traceback.py	Sun Sep 24 14:50:24 2006
@@ -149,6 +149,10 @@
         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)

Modified: python/trunk/Lib/traceback.py
==============================================================================
--- python/trunk/Lib/traceback.py	(original)
+++ python/trunk/Lib/traceback.py	Sun Sep 24 14:50:24 2006
@@ -170,7 +170,7 @@
     # 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__

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Sep 24 14:50:24 2006
@@ -56,6 +56,10 @@
 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).
 


More information about the Python-checkins mailing list