mirror of https://github.com/python/cpython
gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole (#119557)
This commit is contained in:
parent
c0faade891
commit
86d1a1aa88
|
@ -101,7 +101,7 @@ class InteractiveColoredConsole(code.InteractiveConsole):
|
|||
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
|
||||
|
||||
|
|
|
@ -94,6 +94,14 @@ class TestSimpleInteract(unittest.TestCase):
|
|||
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()
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Catch :exc:`SyntaxError` from :func:`compile` in the runsource() method of
|
||||
the InteractiveColoredConsole. Patch by Sergey B Kirpichev.
|
Loading…
Reference in New Issue