https://github.com/python/cpython/commit/5503a5e0997740573b68d924535aa87ee4d36d79 commit: 5503a5e0997740573b68d924535aa87ee4d36d79 branch: main author: Aniket <[email protected]> committer: terryjreedy <[email protected]> date: 2026-10-20T22:18:24-04:00 summary:
gh-152490: Fix TypeError when traceback.py formats SyntaxError(NotImplemented) (#152495) Method traceback.TracebackException._format_syntax_error contains line `msg = self.msg or "<no detail available>"`. Since 3.14, bool(NotImplemented) raises TypeError and hence so does `self.msg or ...`. Catch it in a try statement. --------- Co-authored-by: Terry Jan Reedy <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]> files: A Misc/NEWS.d/next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst M Lib/test/test_traceback.py M Lib/traceback.py diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 678538eb2539c7..40663e7d887e14 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -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() diff --git a/Lib/traceback.py b/Lib/traceback.py index 9c34624b90460a..3ecb1dd318fbcb 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -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, diff --git a/Misc/NEWS.d/next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst b/Misc/NEWS.d/next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst new file mode 100644 index 00000000000000..70429574990997 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst @@ -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. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
