FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Issue #27348: Restore “Exception: None” formatting in traceback module · python/cpython@bb8b1cb · GitHub

Repository navigation

Commit bb8b1cb

Browse files
committed
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.
1 parent 92bb90a commit bb8b1cb

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

‎Lib/_pydecimal.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4106,7 +4106,7 @@ def create_decimal_from_float(self, f):
41064106
>>> context.create_decimal_from_float(3.1415926535897932)
41074107
Traceback (most recent call last):
41084108
...
4109-
decimal.Inexact
4109+
decimal.Inexact: None
41104110
41114111
"""
41124112
d = Decimal.from_float(f) # An exact conversion

‎Lib/test/test_traceback.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
test_tb = namedtuple('tb', ['tb_frame', 'tb_lineno', 'tb_next'])
2020

2121

22-
class SyntaxTracebackCases(unittest.TestCase):
22+
class TracebackCases(unittest.TestCase):
2323
# For now, a very minimal set of tests. I want to be sure that
2424
# formatting of SyntaxErrors works based on changes for 2.1.
2525

@@ -106,10 +106,6 @@ def __str__(self):
106106
str_name = '.'.join([X.__module__, X.__qualname__])
107107
self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value))
108108

109-
def test_without_exception(self):
110-
err = traceback.format_exception_only(None, None)
111-
self.assertEqual(err, ['None\n'])
112-
113109
def test_encoded_file(self):
114110
# Test that tracebacks are correctly printed for encoded source files:
115111
# - correct line number (Issue2384)
@@ -456,6 +452,17 @@ def e():
456452
msg = self.get_report(e).splitlines()
457453
self.assertEqual(msg[-2], ' ^')
458454

455+
def test_message_none(self):
456+
# A message that looks like "None" should not be treated specially
457+
err = self.get_report(Exception(None))
458+
self.assertIn('Exception: None\n', err)
459+
err = self.get_report(Exception('None'))
460+
self.assertIn('Exception: None\n', err)
461+
err = self.get_report(Exception())
462+
self.assertIn('Exception\n', err)
463+
err = self.get_report(Exception(''))
464+
self.assertIn('Exception\n', err)
465+
459466

460467
class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
461468
#

‎Lib/traceback.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def format_exception_only(etype, value):
140140

141141
def _format_final_exc_line(etype, value):
142142
valuestr = _some_str(value)
143-
if value == 'None' or value is None or not valuestr:
143+
if value is None or not valuestr:
144144
line = "%s\n" % etype
145145
else:
146146
line = "%s: %s\n" % (etype, valuestr)

‎Misc/NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ Core and Builtins
7777
Library
7878
-------
7979

80+
- Issue #27348: In the traceback module, restore the formatting of exception
81+
messages like "Exception: None". This fixes a regression introduced in
82+
3.5a2.
83+
8084
- Issue #25651: Allow falsy values to be used for msg parameter of subTest().
8185

8286
- Issue #27932: Prevent memory leak in win32_ver().

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL