mirror of https://github.com/python/cpython
Patch #860326: traceback.format_exception_only() now prepends the
exception's module name to non-builtin exceptions, like the interpreter itself does.
This commit is contained in:
parent
64029986bc
commit
24c274f5dc
|
@ -5,6 +5,9 @@ from test.test_support import run_unittest, is_jython
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
class TbError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class TracebackCases(unittest.TestCase):
|
class TracebackCases(unittest.TestCase):
|
||||||
# For now, a very minimal set of tests. I want to be sure that
|
# For now, a very minimal set of tests. I want to be sure that
|
||||||
# formatting of SyntaxErrors works based on changes for 2.1.
|
# formatting of SyntaxErrors works based on changes for 2.1.
|
||||||
|
@ -103,6 +106,24 @@ def test():
|
||||||
import sys
|
import sys
|
||||||
sys.exc_traceback.__members__
|
sys.exc_traceback.__members__
|
||||||
|
|
||||||
|
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():
|
def test_main():
|
||||||
run_unittest(TracebackCases)
|
run_unittest(TracebackCases)
|
||||||
|
|
||||||
|
|
|
@ -158,8 +158,12 @@ def format_exception_only(etype, value):
|
||||||
"""
|
"""
|
||||||
list = []
|
list = []
|
||||||
if (type(etype) == types.ClassType
|
if (type(etype) == types.ClassType
|
||||||
or (isinstance(etype, type) and issubclass(etype, Exception))):
|
or (isinstance(etype, type) and issubclass(etype, BaseException))):
|
||||||
stype = etype.__name__
|
stype = etype.__name__
|
||||||
|
if not hasattr(etype, '__module__'):
|
||||||
|
stype = '<unknown>.' + stype
|
||||||
|
elif etype.__module__ != 'exceptions':
|
||||||
|
stype = etype.__module__ + '.' + stype
|
||||||
else:
|
else:
|
||||||
stype = etype
|
stype = etype
|
||||||
if value is None:
|
if value is None:
|
||||||
|
|
|
@ -49,6 +49,10 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Patch #860326: traceback.format_exception_only() now prepends the
|
||||||
|
exception's module name to non-builtin exceptions, like the interpreter
|
||||||
|
itself does.
|
||||||
|
|
||||||
- SimpleXMLRPCServer relied on the fcntl module, which is unavailable on
|
- SimpleXMLRPCServer relied on the fcntl module, which is unavailable on
|
||||||
Windows. Bug #1469163.
|
Windows. Bug #1469163.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue