8000 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
Prev Previous commit
Next Next commit
Show warnings once
  • Loading branch information
csabella authored May 26, 2020
commit a20cf7c9fdd0543796a6fce617f1d8671bf76edd
4 changes: 3 additions & 1 deletion Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,9 @@ def runsource(self, source):
# self.write("Unsupported characters in input\n")
# return
# II.runsource() calls .runcode(), overridden below.
return InteractiveInterpreter.runsource(self, source, filename)
with warnings.catch_warnings():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

Just remember to remove the commented out code above before merging...

Copy link
Member Author
@terryjreedy terryjreedy May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I created the PR on 2019 Aug 16, runsource comprised stuffsource(), a comment and assert, the inactivated code, and a try-finally block that wapped the override comment II.runsource() and and that fiddled with warnings in 'finally'.

The comment and assert were added and the code inactivated by MvL in 2007. The commit message was "Expect that source strings are unicode". Since str was bytes at the time, the message, comment, and assert do not make much sense to me. In any case, the comment and assert can be deleted. If IDLE were to pass bytes, there would be an error anyway.

I removed the inactivated code on Sept 16 in #16198 for bpo-38183 as an unrelated change. (A separate PR would have been better.) I only left it in the merge resolution because I was not sure then it should go (it should).

The try-finally was from KBK in 2001 and 2004. On Aug 26, in #15500 for this same issue (bpo-37824), I redid shell warnings and removed 'try' and the finally block, leaving the comment and II.runsource(). As for Cheryl's addition of a warnings filter, I will test and see if it should go in the warnings code to be executed just once and before running any user code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that II.runsource is only use for code input after '>>>'. For instance, 'python -m idlelib -c "0 is "' only prints the warning once even without the filter. The patch otherwise moves it from the console to Shell. The current file level warnings manipulation does not save and restore filters. So I will leave the filter here until such time as code or codeop are patched (see issue) to make it unneeded in IDLE.

warnings.filterwarnings('once')
return InteractiveInterpreter.runsource(self, source, filename)

def stuffsource(self, source):
"Stuff source in the filename cache"
Expand Down
0