[Python-checkins] r45322 - in python/branches/release24-maint: Lib/test/test_traceback.py Lib/traceback.py Misc/NEWS
georg.brandl
python-checkins at python.org
Wed Apr 12 23:14:13 CEST 2006
Author: georg.brandl
Date: Wed Apr 12 23:14:12 2006
New Revision: 45322
Modified:
python/branches/release24-maint/Lib/test/test_traceback.py
python/branches/release24-maint/Lib/traceback.py
python/branches/release24-maint/Misc/NEWS
Log:
Patch #860326: traceback.format_exception_only() now prepends the
exception's module name to non-builtin exceptions, like the interpreter
itself does.
(backport from rev. 45321)
Modified: python/branches/release24-maint/Lib/test/test_traceback.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_traceback.py (original)
+++ python/branches/release24-maint/Lib/test/test_traceback.py Wed Apr 12 23:14:12 2006
@@ -5,6 +5,9 @@
import traceback
+class TbError(Exception):
+ pass
+
class TracebackCases(unittest.TestCase):
# For now, a very minimal set of tests. I want to be sure that
# formatting of SyntaxErrors works based on changes for 2.1.
@@ -85,6 +88,24 @@
os.unlink(os.path.join(testdir, f))
os.rmdir(testdir)
+ def raise_tberror(self):
+ raise TbError
+
+ def raise_typeerror(self):
+ raise TypeError
+
+ def test_modulename(self):
+ # Bug 860326: format_exception_only should prepend module name
+ # to exceptions not in "exceptions", like PyErr_Print does.
+ err = self.get_exception_format(self.raise_tberror, TbError)
+ self.assertEquals(len(err), 1)
+ self.assert_(err[0] == '__main__.TbError\n' or
+ err[0] == 'test.test_traceback.TbError\n')
+
+ err = self.get_exception_format(self.raise_typeerror, TypeError)
+ self.assertEquals(err[0], 'TypeError\n')
+
+
def test_main():
run_unittest(TracebackCases)
Modified: python/branches/release24-maint/Lib/traceback.py
==============================================================================
--- python/branches/release24-maint/Lib/traceback.py (original)
+++ python/branches/release24-maint/Lib/traceback.py Wed Apr 12 23:14:12 2006
@@ -159,6 +159,10 @@
list = []
if type(etype) == types.ClassType:
stype = etype.__name__
+ if not hasattr(etype, '__module__'):
+ stype = '<unknown>.' + stype
+ elif etype.__module__ != 'exceptions':
+ stype = etype.__module__ + '.' + stype
else:
stype = etype
if value is None:
Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS (original)
+++ python/branches/release24-maint/Misc/NEWS Wed Apr 12 23:14:12 2006
@@ -23,6 +23,10 @@
Library
-------
+- Patch #860326: traceback.format_exception_only() now prepends the
+ exception's module name to non-builtin exceptions, like the interpreter
+ itself does.
+
- The email module's parsedate_tz function now sets the daylight savings
flag to -1 (unknown) since it can't tell from the date whether it should
be set.
More information about the Python-checkins
mailing list