]> granicus.if.org Git - python/commitdiff
Issue #27348: Restore “Exception: None” formatting in traceback module
authorMartin Panter <vadmium+py@gmail.com>
Thu, 22 Sep 2016 09:37:39 +0000 (09:37 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Thu, 22 Sep 2016 09:37:39 +0000 (09:37 +0000)
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.

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

index 900a1a796c026a125b507d1d9fa345a4da60894b..a5ea340e9d4aba56406f0f2c2a1d4bf1295b301f 100644 (file)
@@ -4106,7 +4106,7 @@ class Context(object):
         >>> 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
index 549d8d1e9701837d8d0b66505ba503ec284940d8..b4b74d3fccc0da81f9eb77436bd3b49ec0173d90 100644 (file)
@@ -19,7 +19,7 @@ test_frame = namedtuple('frame', ['f_code', 'f_globals', 'f_locals'])
 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 @@ class SyntaxTracebackCases(unittest.TestCase):
             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)
@@ -456,6 +452,17 @@ class BaseExceptionReportingTests:
         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):
     #
index a2eb539c02587a104aea5be25171be491466f5cc..c5fd61716c762c26d522c48ba110a90c1783317d 100644 (file)
@@ -140,7 +140,7 @@ def format_exception_only(etype, value):
 
 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)
index e6970a45798af0a923754d22d492f4dfc201ba0e..4d2fc0a39b7eba5ed05a550acc19e0842528d07a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -77,6 +77,10 @@ Core and Builtins
 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 #25651: Allow falsy values to be used for msg parameter of subTest().
 
 - Issue #27932: Prevent memory leak in win32_ver().