8000 [3.13] gh-119555: catch SyntaxError from compile() in the Interactive… · python/cpython@40a024c · GitHub
[go: up one dir, main page]

Skip to content

Commit 40a024c

Browse files
[3.13] gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole (GH-119557) (#119709)
1 parent 48c7776 commit 40a024c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/_pyrepl/simple_interact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
9696
item = wrapper([stmt])
9797
try:
9898
code = compile(item, filename, the_symbol, dont_inherit=True)
99-
except (OverflowError, ValueError):
99+
except (OverflowError, ValueError, SyntaxError):
100100
self.showsyntaxerror(filename)
101101
return False
102102

Lib/test/test_pyrepl/test_interact.py

Lines changed: 8 additions & 0 deletions
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()
Lines changed: 2 additions & 0 deletions
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)
0