# HG changeset patch # Parent 57f3514564f62b93847d3867c3a4ff41a082cc92 Issue #27348: Restore “Exception: None” formatting in traceback module This fixes a regression caused by revision 73afda5a4e4c. Also reverts the decimal test workaround added in revision 5f3dd0a2b1ab. Remove test_without_exception(). According to revision ecaafc32c500, this was added in Python 2 so that print_exc() would output “None” when called with no exception set. However print_exc() never worked like this in Python 3, and the use case is not documented. Restore TracebackCases class name (instead of SyntaxTracebackCases), because the class also tests other exceptions. diff -r 57f3514564f6 Lib/_pydecimal.py --- a/Lib/_pydecimal.py Tue Jun 28 10:12:22 2016 -0700 +++ b/Lib/_pydecimal.py Wed Jun 29 08:44:17 2016 +0000 @@ -4157,7 +4157,7 @@ >>> context.create_decimal_from_float(3.1415926535897932) Traceback (most recent call last): ... - decimal.Inexact + decimal.Inexact: None """ d = Decimal.from_float(f) # An exact conversion diff -r 57f3514564f6 Lib/test/test_traceback.py --- a/Lib/test/test_traceback.py Tue Jun 28 10:12:22 2016 -0700 +++ b/Lib/test/test_traceback.py Wed Jun 29 08:44:17 2016 +0000 @@ -19,7 +19,7 @@ test_tb = namedtuple('tb', ['tb_frame', 'tb_lineno', 'tb_next']) -class SyntaxTracebackCases(unittest.TestCase): +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. @@ -106,10 +106,6 @@ str_name = '.'.join([X.__module__, X.__qualname__]) self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value)) - def test_without_exception(self): - err = traceback.format_exception_only(None, None) - self.assertEqual(err, ['None\n']) - def test_encoded_file(self): # Test that tracebacks are correctly printed for encoded source files: # - correct line number (Issue2384) @@ -455,6 +451,17 @@ msg = self.get_report(e).splitlines() self.assertEqual(msg[-2], ' ^') + def test_message_none(self): + # A message that looks like "None" should not be treated specially + err = self.get_report(Exception(None)) + self.assertIn('Exception: None\n', err) + err = self.get_report(Exception('None')) + self.assertIn('Exception: None\n', err) + err = self.get_report(Exception()) + self.assertIn('Exception\n', err) + err = self.get_report(Exception('')) + self.assertIn('Exception\n', err) + class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase): # diff -r 57f3514564f6 Lib/traceback.py --- a/Lib/traceback.py Tue Jun 28 10:12:22 2016 -0700 +++ b/Lib/traceback.py Wed Jun 29 08:44:17 2016 +0000 @@ -140,7 +140,7 @@ def _format_final_exc_line(etype, value): valuestr = _some_str(value) - if value == 'None' or value is None or not valuestr: + if value is None or not valuestr: line = "%s\n" % etype else: line = "%s: %s\n" % (etype, valuestr) diff -r 57f3514564f6 Misc/NEWS --- a/Misc/NEWS Tue Jun 28 10:12:22 2016 -0700 +++ b/Misc/NEWS Wed Jun 29 08:44:17 2016 +0000 @@ -10,6 +10,10 @@ Library ------- +- Issue #27348: In the traceback module, restore the formatting of exception + messages like "Exception: None". This fixes a regression introduced in + 3.5a2. + - Issue #22115: Added methods trace_add, trace_remove and trace_info in the tkinter.Variable class. They replace old methods trace_variable, trace, trace_vdelete and trace_vinfo that use obsolete Tcl commands and might