From 23988cf11df5ebcb297ea7ffdc0ccc2467655315 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sat, 25 May 2024 20:15:53 +0300 Subject: [PATCH 1/2] gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole --- Lib/_pyrepl/simple_interact.py | 2 +- Lib/test/test_pyrepl/test_interact.py | 8 ++++++++ .../2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py index 8ab4dab757685e..f6857c59679f7d 100644 --- a/Lib/_pyrepl/simple_interact.py +++ b/Lib/_pyrepl/simple_interact.py @@ -96,7 +96,7 @@ def runsource(self, source, filename="", symbol="single"): item = wrapper([stmt]) try: code = compile(item, filename, the_symbol) - except (OverflowError, ValueError): + except (OverflowError, ValueError, SyntaxError): self.showsyntaxerror(filename) return False diff --git a/Lib/test/test_pyrepl/test_interact.py b/Lib/test/test_pyrepl/test_interact.py index 10e34045bcf92d..fd85fab8ca0b0e 100644 --- a/Lib/test/test_pyrepl/test_interact.py +++ b/Lib/test/test_pyrepl/test_interact.py @@ -94,3 +94,11 @@ def test_runsource_shows_syntax_error_for_failed_compilation(self): with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror: console.runsource(source) mock_showsyntaxerror.assert_called_once() + source = dedent("""\ + match 1: + case {0: _, 0j: _}: + pass + """) + with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror: + console.runsource(source) + mock_showsyntaxerror.assert_called_once() diff --git a/Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst b/Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst new file mode 100644 index 00000000000000..9d152ce7d55316 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst @@ -0,0 +1,2 @@ +Catch :exc:`SyntaxError` from :func:`complie` in the runsource() method of +the InteractiveColoredConsole. Patch by Sergey B Kirpichev. From 2b57989cc5f585724a6120ba54d543e87e57b86b Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sat, 25 May 2024 20:22:30 +0300 Subject: [PATCH 2/2] + typo --- .../next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst b/Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst index 9d152ce7d55316..e16cb28b471a7a 100644 --- a/Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst +++ b/Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst @@ -1,2 +1,2 @@ -Catch :exc:`SyntaxError` from :func:`complie` in the runsource() method of +Catch :exc:`SyntaxError` from :func:`compile` in the runsource() method of the InteractiveColoredConsole. Patch by Sergey B Kirpichev.