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
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
6 changes: 5 additions & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,11 @@ def _format_syntax_error(self, stype, **kwargs):
)
else:
yield ' {}\n'.format(ltext)
msg = self.msg or "<no detail available>"
try:
if not (msg := self.msg):
msg = "<no detail available>"
except TypeError:
pass
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