summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-05-29 11:04:45 (GMT)
committerGitHub <noreply@github.com>2024-05-29 11:04:45 (GMT)
commit40a024c9835cddd85f14bab4b1e8f6545a621208 (patch)
tree68466bee4878bccd99a23d83d5bacf436142b6a3 /Lib
parent48c777688305bfa45038a15ab09c03350503a2c4 (diff)
downloadcpython-40a024c9835cddd85f14bab4b1e8f6545a621208.zip
cpython-40a024c9835cddd85f14bab4b1e8f6545a621208.tar.gz
cpython-40a024c9835cddd85f14bab4b1e8f6545a621208.tar.bz2
[3.13] gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole (GH-119557) (#119709)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/_pyrepl/simple_interact.py2
-rw-r--r--Lib/test/test_pyrepl/test_interact.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py
index 3dfb1d7..1568a73 100644
--- a/Lib/_pyrepl/simple_interact.py
+++ b/Lib/_pyrepl/simple_interact.py
@@ -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
diff --git a/Lib/test/test_pyrepl/test_interact.py b/Lib/test/test_pyrepl/test_interact.py
index 6ebd51f..4d01ea7 100644
--- a/Lib/test/test_pyrepl/test_interact.py
+++ b/Lib/test/test_pyrepl/test_interact.py
@@ -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()