]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 29 May 2024 11:04:45 +0000 (13:04 +0200)
committerGitHub <noreply@github.com>
Wed, 29 May 2024 11:04:45 +0000 (12:04 +0100)
Lib/_pyrepl/simple_interact.py
Lib/test/test_pyrepl/test_interact.py
Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst [new file with mode: 0644]

index 3dfb1d7ad736e3e29cab83cb6a9ebf8b8a254974..1568a73c1b5ec0c3463d7fc8acb8ce0cd304880d 100644 (file)
@@ -96,7 +96,7 @@ class InteractiveColoredConsole(code.InteractiveConsole):
             item = wrapper([stmt])
             try:
                 code = compile(item, filename, the_symbol, dont_inherit=True)
-            except (OverflowError, ValueError):
+            except (OverflowError, ValueError, SyntaxError):
                     self.showsyntaxerror(filename)
                     return False
 
index 6ebd51fe14dd62247d841812822237ab15816366..4d01ea7620109d2a494fc5755235f17de71c8f7c 100644 (file)
@@ -94,6 +94,14 @@ class TestSimpleInteract(unittest.TestCase):
         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()
 
     def test_no_active_future(self):
         console = InteractiveColoredConsole()
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 (file)
index 0000000..e16cb28
--- /dev/null
@@ -0,0 +1,2 @@
+Catch :exc:`SyntaxError` from :func:`compile` in the runsource() method of
+the InteractiveColoredConsole.  Patch by Sergey B Kirpichev.