[Python-checkins] cpython (merge 3.6 -> default): Issue #27348: Merge exception formatting fix from 3.6

martin.panter python-checkins at python.org
Thu Sep 22 06:56:37 EDT 2016


https://hg.python.org/cpython/rev/4261ae29d3e2
changeset:   104009:4261ae29d3e2
parent:      104004:6911917f1f02
parent:      104007:d1455d14accd
user:        Martin Panter <vadmium+py at gmail.com>
date:        Thu Sep 22 10:34:25 2016 +0000
summary:
  Issue #27348: Merge exception formatting fix from 3.6

files:
  Lib/_pydecimal.py          |   2 +-
  Lib/test/test_traceback.py |  17 ++++++++++++-----
  Lib/traceback.py           |   2 +-
  Misc/NEWS                  |   4 ++++
  4 files changed, 18 insertions(+), 7 deletions(-)


diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py
--- a/Lib/_pydecimal.py
+++ b/Lib/_pydecimal.py
@@ -4156,7 +4156,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 --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -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)
@@ -587,6 +583,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 --git a/Lib/traceback.py b/Lib/traceback.py
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -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 --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -41,6 +41,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 #25651: Allow falsy values to be used for msg parameter of subTest().
 
 - Issue #27778: Fix a memory leak in os.getrandom() when the getrandom() is

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list