https://github.com/python/cpython/commit/86d1a1aa8841ea182eaf434ae6b942b3e93f58db
commit: 86d1a1aa8841ea182eaf434ae6b942b3e93f58db
branch: main
author: Sergey B Kirpichev <[email protected]>
committer: pablogsal <[email protected]>
date: 2024-05-29T07:57:50+01:00
summary:
gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole
(#119557)
files:
A Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst
M Lib/_pyrepl/simple_interact.py
M Lib/test/test_pyrepl/test_interact.py
diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py
index b5f182ebfe710b..11e831c1d6c5d4 100644
--- a/Lib/_pyrepl/simple_interact.py
+++ b/Lib/_pyrepl/simple_interact.py
@@ -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
diff --git a/Lib/test/test_pyrepl/test_interact.py
b/Lib/test/test_pyrepl/test_interact.py
index 6ebd51fe14dd62..4d01ea7620109d 100644
--- a/Lib/test/test_pyrepl/test_interact.py
+++ b/Lib/test/test_pyrepl/test_interact.py
@@ -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()
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
index 00000000000000..e16cb28b471a7a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-05-25-20-15-26.gh-issue-119555.mvHbEL.rst
@@ -0,0 +1,2 @@
+Catch :exc:`SyntaxError` from :func:`compile` in the runsource() method of
+the InteractiveColoredConsole. Patch by Sergey B Kirpichev.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]