diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-09-22 10:33:21 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-09-22 10:33:21 (GMT) |
commit | f3b0639417bf788d9a7133ec26e52c406e6c8f4c (patch) | |
tree | fb4cad9ccebc8abd965b5e1a5bb272d44976a75d /Lib | |
parent | e3d504090cea1c4e01e9d8ebf241f9356cb1aba0 (diff) | |
parent | bb8b1cb6af830b40f9be398d1e1bf8bdca772140 (diff) | |
download | cpython-f3b0639417bf788d9a7133ec26e52c406e6c8f4c.zip cpython-f3b0639417bf788d9a7133ec26e52c406e6c8f4c.tar.gz cpython-f3b0639417bf788d9a7133ec26e52c406e6c8f4c.tar.bz2 |
Issue #27348: Merge exception formatting fix from 3.5 into 3.6
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/_pydecimal.py | 2 | ||||
-rw-r--r-- | Lib/test/test_traceback.py | 17 | ||||
-rw-r--r-- | Lib/traceback.py | 2 |
3 files changed, 14 insertions, 7 deletions
diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py index 6318a49..0b40928 100644 --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -4156,7 +4156,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 diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index ac067bf..f2dc650 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -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) @@ -587,6 +583,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): # diff --git a/Lib/traceback.py b/Lib/traceback.py index a1cb5fb..09bda71 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -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) |