Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,18 @@ def test_format_exception_only_exc(self):
output = traceback.format_exception_only(Exception("projector"))
self.assertEqual(output, ["Exception: projector\n"])

def test_format_syntax_error_msg(self):
exc = SyntaxError(NotImplemented)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And create a separate test ror those cases.

lines = traceback.format_exception_only(type(exc), exc)
result = "".join(lines)
self.assertIn("NotImplemented", result)

exc = SyntaxError("invalid syntax")
lines = traceback.format_exception_only(type(exc), exc)
result = "".join(lines)
self.assertIn("SyntaxError", result)
self.assertIn("invalid syntax", 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 is None or self.msg == '':
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