Skip to content

Commit

Permalink
[3.13] gh-119555: catch SyntaxError from compile() in the Interactive…
Browse files Browse the repository at this point in the history
…ColoredConsole (GH-119557) (#119709)
  • Loading branch information
miss-islington committed May 29, 2024
1 parent 48c7776 commit 40a024c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
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

Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_pyrepl/test_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ 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()

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

0 comments on commit 40a024c

Please sign in to comment.