From 4663913ee0e05e0fb8e9459aa66fe2a8fe3122de Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sun, 28 Jun 2026 14:32:24 +0000 Subject: [PATCH 01/14] Fix TypeError when formatting SyntaxError with msg=NotImplemented in traceback.py --- Lib/test/test_traceback.py | 5 +++++ Lib/traceback.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index e38d0942e463e9c..26eada434204af7 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -625,6 +625,11 @@ def test_signatures(self): str(inspect.signature(traceback.format_exception_only)), '(exc, /, value=, *, show_group=False, **kwargs)') + def test_syntax_error_with_not_implemented_msg(self): + exc = SyntaxError(NotImplemented) + lines = traceback.format_exception_only(type(exc), exc) + self.assertIsInstance("".join(lines), str) + class PurePythonExceptionFormattingMixin: def get_exception(self, callable, slice_start=0, slice_end=-1): diff --git a/Lib/traceback.py b/Lib/traceback.py index dcdab1f12e9a168..b9585db021b1fa1 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -1611,7 +1611,10 @@ def _format_syntax_error(self, stype, **kwargs): ) else: yield ' {}\n'.format(ltext) - msg = self.msg or "" + if self.msg is None: + msg = "" + else: + msg = str(self.msg) yield "{}{}{}: {}{}{}{}\n".format( theme.type, stype, From 03a2e53b021db9d785dd3e851aa866a825517fc7 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 28 Jun 2026 14:37:03 +0000 Subject: [PATCH 02/14] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst 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 000000000000000..5252f0b12fe03b9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst @@ -0,0 +1,2 @@ +Fix :exc:`TypeError` when formatting a :exc:`SyntaxError` raised with :data:`NotImplemented` as its argument, which caused IDLE Shell to restart +unexpectedly. From 83fc00eb9481d2602ac2c0c8e99e616f3420592b Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Sun, 28 Jun 2026 20:10:15 +0530 Subject: [PATCH 03/14] fix format --- .../Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 index 5252f0b12fe03b9..2d99b0799b40245 100644 --- 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 @@ -1,2 +1 @@ -Fix :exc:`TypeError` when formatting a :exc:`SyntaxError` raised with :data:`NotImplemented` as its argument, which caused IDLE Shell to restart -unexpectedly. +Fix :exc:`TypeError` when formatting a :exc:`SyntaxError` raised with :data:`NotImplemented` as its argument, which caused IDLE Shell to restart unexpectedly. From e6c02184d740b29de4a57d21d3a1f782665fda41 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sun, 28 Jun 2026 18:39:27 +0000 Subject: [PATCH 04/14] rename and update test --- Lib/test/test_traceback.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 26eada434204af7..04b865e14d5d4e6 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -583,10 +583,20 @@ def test_format_exception_exc(self): with self.assertRaisesRegex(TypeError, 'required positional argument'): traceback.format_exception(exc=e) - def test_format_exception_only_exc(self): + def test_format_syntax_error(self): output = traceback.format_exception_only(Exception("projector")) self.assertEqual(output, ["Exception: projector\n"]) + exc = SyntaxError(NotImplemented) + lines = traceback.format_exception_only(type(exc), exc) + self.assertIsInstance("".join(lines), str) + + 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() @@ -625,11 +635,6 @@ def test_signatures(self): str(inspect.signature(traceback.format_exception_only)), '(exc, /, value=, *, show_group=False, **kwargs)') - def test_syntax_error_with_not_implemented_msg(self): - exc = SyntaxError(NotImplemented) - lines = traceback.format_exception_only(type(exc), exc) - self.assertIsInstance("".join(lines), str) - class PurePythonExceptionFormattingMixin: def get_exception(self, callable, slice_start=0, slice_end=-1): From e68c5216389c81d66337d72f768d6c050400ddde Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Mon, 29 Jun 2026 06:37:23 +0530 Subject: [PATCH 05/14] Update Misc/NEWS.d/next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst Co-authored-by: Terry Jan Reedy --- .../next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 2d99b0799b40245..ddf205cb11a9b29 100644 --- 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 @@ -1 +1 @@ -Fix :exc:`TypeError` when formatting a :exc:`SyntaxError` raised with :data:`NotImplemented` as its argument, which caused IDLE Shell to restart unexpectedly. +Fix :exc:`TypeError` when formatting a :exc:`SyntaxError` raised with :data:`NotImplemented` as its argument, which caused unexpected REPL exit and IDLE Shell restart. From 16bfcd2392407de19c491916c23d3be9af299e0a Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Mon, 29 Jun 2026 06:57:14 +0530 Subject: [PATCH 06/14] Update Lib/traceback.py Co-authored-by: Terry Jan Reedy --- Lib/traceback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index b9585db021b1fa1..e9f284660a61395 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -1611,7 +1611,7 @@ def _format_syntax_error(self, stype, **kwargs): ) else: yield ' {}\n'.format(ltext) - if self.msg is None: + if self.msg is None or self.msg == '': msg = "" else: msg = str(self.msg) From 0c5b7114db7ab6e4b4b54c0f8019f6f8e3b45d15 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Mon, 29 Jun 2026 12:54:17 +0000 Subject: [PATCH 07/14] update tests --- Lib/test/test_traceback.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 04b865e14d5d4e6..e72c2e53c5aba07 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -583,13 +583,15 @@ def test_format_exception_exc(self): with self.assertRaisesRegex(TypeError, 'required positional argument'): traceback.format_exception(exc=e) - def test_format_syntax_error(self): + 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) lines = traceback.format_exception_only(type(exc), exc) - self.assertIsInstance("".join(lines), str) + result = "".join(lines) + self.assertIn("NotImplemented", result) exc = SyntaxError("invalid syntax") lines = traceback.format_exception_only(type(exc), exc) From 18295d5a68382bf6044e9b3b4b5e76886b34e9e4 Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Sun, 6 Sep 2026 20:33:37 +0530 Subject: [PATCH 08/14] Update Lib/traceback.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/traceback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index e9f284660a61395..67eeb9f9419c283 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -1611,7 +1611,7 @@ def _format_syntax_error(self, stype, **kwargs): ) else: yield ' {}\n'.format(ltext) - if self.msg is None or self.msg == '': + if self.msg in (None, ''): msg = "" else: msg = str(self.msg) From 52f329d06d17a9b9e2af72919c8b36a9bad8c51b Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Sun, 6 Sep 2026 20:33:53 +0530 Subject: [PATCH 09/14] Update Lib/test/test_traceback.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/test/test_traceback.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index e72c2e53c5aba07..a49d077ef9542f5 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -587,17 +587,12 @@ 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) + @support.subTests("arg", [NotImplemented, "invalid syntax"]) + def test_format_syntax_error_message(self, arg): + exc = SyntaxError(value) 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) + self.assertIn(str(arg), result) def test_exception_is_None(self): NONE_EXC_STRING = 'NoneType: None\n' From e4d9b2479318be70b8ad0904d176e8cf3071ba43 Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Sun, 6 Sep 2026 20:35:46 +0530 Subject: [PATCH 10/14] Update Lib/test/test_traceback.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/test/test_traceback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index a49d077ef9542f5..32a8aabfe76cf84 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -589,7 +589,7 @@ def test_format_exception_only_exc(self): @support.subTests("arg", [NotImplemented, "invalid syntax"]) def test_format_syntax_error_message(self, arg): - exc = SyntaxError(value) + exc = SyntaxError(arg) lines = traceback.format_exception_only(type(exc), exc) result = "".join(lines) self.assertIn(str(arg), result) From 0e62eba37c937767b6df6d60b14ebb535b843dee Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Mon, 19 Oct 2026 09:48:14 +0530 Subject: [PATCH 11/14] Update Lib/traceback.py Co-authored-by: Terry Jan Reedy --- Lib/traceback.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index 67eeb9f9419c283..4a696baea702a4a 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -1614,7 +1614,10 @@ def _format_syntax_error(self, stype, **kwargs): if self.msg in (None, ''): msg = "" else: - msg = str(self.msg) + try: + (msg := m) or (msg :="") + except TypeError: + pass yield "{}{}{}: {}{}{}{}\n".format( theme.type, stype, From 576a8c4f1b9faacca104e73c2e439ed04313606b Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Mon, 19 Oct 2026 10:11:17 +0530 Subject: [PATCH 12/14] Apply review suggestion --- Lib/traceback.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index 4a696baea702a4a..b81b326ab1b23bd 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -1611,11 +1611,9 @@ def _format_syntax_error(self, stype, **kwargs): ) else: yield ' {}\n'.format(ltext) - if self.msg in (None, ''): - msg = "" - else: try: - (msg := m) or (msg :="") + if not (msg := self.msg): + msg = "" except TypeError: pass yield "{}{}{}: {}{}{}{}\n".format( From ac1d1d2d735e80c513a134cbbdc38395286ac67a Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Mon, 19 Oct 2026 10:14:35 +0530 Subject: [PATCH 13/14] Fix TypeError formatting SyntaxError with NotImplemented From 084abb9d0b80b847b86e1ebfc908e07fd6a4e671 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Tue, 20 Oct 2026 10:18:22 +0530 Subject: [PATCH 14/14] Fix line endings in NEWS entry --- .../next/Library/2026-06-28-14-37-01.gh-issue-152490.A8qLbF.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index ddf205cb11a9b29..704295749909974 100644 --- 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 @@ -1 +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. +Fix :exc:`TypeError` when formatting a :exc:`SyntaxError` raised with :data:`NotImplemented` as its argument, which caused unexpected REPL exit and IDLE Shell restart.