Skip to content
7 changes: 7 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,13 @@ def test_format_exception_only_exc(self):
output = traceback.format_exception_only(Exception("projector"))
self.assertEqual(output, ["Exception: projector\n"])

@support.subTests("arg", [NotImplemented, "invalid syntax"])
def test_format_syntax_error_message(self, arg):
exc = SyntaxError(arg)
lines = traceback.format_exception_only(type(exc), exc)
result = "".join(lines)
self.assertIn(str(arg), result)

def test_exception_is_None(self):
NONE_EXC_STRING = 'NoneType: None\n'
excfile = StringIO()
Expand Down
5 changes: 4 additions & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,10 @@ def _format_syntax_error(self, stype, **kwargs):
)
else:
yield ' {}\n'.format(ltext)
msg = self.msg or "<no detail available>"
if self.msg in (None, ''):
msg = "<no detail available>"
else:
msg = str(self.msg)
yield "{}{}{}: {}{}{}{}\n".format(
theme.type,
stype,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :exc:`TypeError` when formatting a :exc:`SyntaxError` raised with :data:`NotImplemented` as its argument, which caused unexpected REPL exit and IDLE Shell restart.
Loading