Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole #119557

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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.
Loading