mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.13] gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole (GH-119557) (#119709)
This commit is contained in:
parent
48c7776883
commit
40a024c983
3 changed files with 11 additions and 1 deletions
|
@ -96,7 +96,7 @@ class InteractiveColoredConsole(code.InteractiveConsole):
|
||||||
item = wrapper([stmt])
|
item = wrapper([stmt])
|
||||||
try:
|
try:
|
||||||
code = compile(item, filename, the_symbol, dont_inherit=True)
|
code = compile(item, filename, the_symbol, dont_inherit=True)
|
||||||
except (OverflowError, ValueError):
|
except (OverflowError, ValueError, SyntaxError):
|
||||||
self.showsyntaxerror(filename)
|
self.showsyntaxerror(filename)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,14 @@ class TestSimpleInteract(unittest.TestCase):
|
||||||
with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror:
|
with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror:
|
||||||
console.runsource(source)
|
console.runsource(source)
|
||||||
mock_showsyntaxerror.assert_called_once()
|
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):
|
def test_no_active_future(self):
|
||||||
console = InteractiveColoredConsole()
|
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…
Add table
Add a link
Reference in a new issue