10000 gh-82005: Properly handle user input warnings in IDLE shell. by terryjreedy · Pull Request #15311 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-82005: Properly handle user input warnings in IDLE shell. #15311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Next Next commit
bpo-37824: Properly handle user input warnings in IDLE shell.
Cease turning SyntaxWarnings into SyntaxErrors. Print warnings
in the shell, not a possibly non-existent command line.
  • Loading branch information
terryjreedy committed Aug 16, 2019
commit eb87bcd12d479fac977a098360b3eba2c6757720
21 changes: 7 additions & 14 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@
HOST = '127.0.0.1' # python execution server on localhost loopback
PORT = 0 # someday pass in host, port for remote debug capability

# Override warnings module to write to warning_stream. Initialize to send IDLE
# internal warnings to the console. ScriptBinding.check_syntax() will
# temporarily redirect the stream to the shell window to display warnings when
# checking user's code.
# Override warnings.show_warning to write to IDLE format to warning_stream.
# Initially send IDLE internal warnings to the console, if present.
# Send to Shell.stderr (traceback stream) when available.
warning_stream = sys.__stderr__ # None, at least on Windows, if no console.

def idle_showwarning(
Expand Down Expand Up @@ -665,8 +664,6 @@ def runsource(self, source):
"Extend base class method: Stuff the source in the line cache first"
filename = self.stuffsource(source)
self.more = 0
self.save_warnings_filters = warnings.filters[:]
warnings.filterwarnings(action="error", category=SyntaxWarning)
# at the moment, InteractiveInterpreter expects str
assert isinstance(source, str)
#if isinstance(source, str):
Expand All @@ -677,14 +674,8 @@ def runsource(self, source):
# self.tkconsole.resetoutput()
# self.write("Unsupported characters in input\n")
# return
try:
# InteractiveInterpreter.runsource() calls its runcode() method,
# which is overridden (see below)
return InteractiveInterpreter.runsource(self, source, filename)
finally:
if self.save_warnings_filters is not None:
warnings.filters[:] = self.save_warnings_filters
self.save_warnings_filters = None
# II.runsource() calls .runcode(), overridden below.
return InteractiveInterpreter.runsource(self, source, filename)

def stuffsource(self, source):
"Stuff source in the filename cache"
Expand Down Expand Up @@ -916,6 +907,8 @@ def __init__(self, flist=None):
sys.stdout = self.stdout
sys.stderr = self.stderr
sys.stdin = self.stdin
global warning_stream
warning_stream = self.stderr
try:
# page help() text to shell.
import pydoc # import must be done here to capture i/o rebinding.
Expand Down
0