Skip to content

Commit 86d1a1a

Browse files
authored
gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole (#119557)
1 parent c0faade commit 86d1a1a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/_pyrepl/simple_interact.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
101101
item = wrapper([stmt])
102102
try:
103103
code = compile(item, filename, the_symbol, dont_inherit=True)
104-
except (OverflowError, ValueError):
104+
except (OverflowError, ValueError, SyntaxError):
105105
self.showsyntaxerror(filename)
106106
return False
107107

Lib/test/test_pyrepl/test_interact.py

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ def test_runsource_shows_syntax_error_for_failed_compilation(self):
9494
with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror:
9595
console.runsource(source)
9696
mock_showsyntaxerror.assert_called_once()
97+
source = dedent("""\
98+
match 1:
99+
case {0: _, 0j: _}:
100+
pass
101+
""")
102+
with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror:
103+
console.runsource(source)
104+
mock_showsyntaxerror.assert_called_once()
97105

98106
def test_no_active_future(self):
99107
console = InteractiveColoredConsole()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Catch :exc:`SyntaxError` from :func:`compile` in the runsource() method of
2+
the InteractiveColoredConsole. Patch by Sergey B Kirpichev.

0 commit comments

Comments
 (0)