Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit86d1a1a

Browse files
authored
gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole (#119557)
1 parentc0faade commit86d1a1a

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
@@ -101,7 +101,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
101101
item=wrapper([stmt])
102102
try:
103103
code=compile(item,filename,the_symbol,dont_inherit=True)
104-
except (OverflowError,ValueError):
104+
except (OverflowError,ValueError,SyntaxError):
105105
self.showsyntaxerror(filename)
106106
returnFalse
107107

‎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
withpatch.object(console,"showsyntaxerror")asmock_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+
withpatch.object(console,"showsyntaxerror")asmock_showsyntaxerror:
103+
console.runsource(source)
104+
mock_showsyntaxerror.assert_called_once()
97105

98106
deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp