Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4ce430

Browse files
committed
Turn SyntasWarning into SyntaxError for all code entered
interactively.
1 parent 55a0034 commit b4ce430

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

Tools/idle/PyShell.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import string
66
import getopt
77
import re
8+
import warnings
89

910
import linecache
1011
from code import InteractiveInterpreter
@@ -180,7 +181,14 @@ def runsource(self, source):
180181
# Extend base class to stuff the source in the line cache first
181182
filename = self.stuffsource(source)
182183
self.more = 0
183-
return InteractiveInterpreter.runsource(self, source, filename)
184+
self.save_warnings_filters = warnings.filters[:]
185+
warnings.filterwarnings(action="error", category=SyntaxWarning)
186+
try:
187+
return InteractiveInterpreter.runsource(self, source, filename)
188+
finally:
189+
if self.save_warnings_filters is not None:
190+
warnings.filters[:] = self.save_warnings_filters
191+
self.save_warnings_filters = None
184192

185193
def stuffsource(self, source):
186194
# Stuff source in the filename cache
@@ -249,6 +257,9 @@ def getdebugger(self):
249257

250258
def runcode(self, code):
251259
# Override base class method
260+
if self.save_warnings_filters is not None:
261+
warnings.filters[:] = self.save_warnings_filters
262+
self.save_warnings_filters = None
252263
debugger = self.debugger
253264
try:
254265
self.tkconsole.beginexecuting()

0 commit comments

Comments
 (0)