https://github.com/python/cpython/commit/da61baf992fdf7407bd9306d5f304f2d83efe228 commit: da61baf992fdf7407bd9306d5f304f2d83efe228 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: terryjreedy <[email protected]> date: 2026-10-21T01:47:29-04:00 summary:
[3.15] gh-152490: Fix TypeError when traceback.py formats SyntaxError(NotImplemented) (GH-152495) (#160009) gh-152490: Fix TypeError when traceback.py formats SyntaxError(NotImplemented) (GH-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. --------- (cherry picked from commit 5503a5e0997740573b68d924535aa87ee4d36d79) Co-authored-by: Aniket <[email protected]> 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 b5a16e4e750be4..e6301ddb40e012 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 9d386754c0eeef..8d24fb4c290486 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -1600,7 +1600,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]
