GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-82005: Properly handle user input warnings in IDLE shell. by terryjreedy · Pull Request #15311 · python/cpython

Conversation

@terryjreedy

@terryjreedy terryjreedy commented Aug 16, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Print warnings in the shell instead of the parent terminal, if there is one.

WIP Bug 1. Each warning printed 3 times. Will look in code.InteractiveInterpreter.
Bug 2. Warning inserted before code being warned about. My guess is that intercepted \n triggers compile which triggers warnings output before \n is passed to tk.Text to be inserted and move iomark. (I do not know when/where iomark is normally moved, but it seems not soon enough when compile warns). Shell.write changes gravity before and after calling OutputWindow.write, which I suspect moves the mark.

  • Issue: IDLE: Handle Shell input SyntaxWarning & DeprecationWarning #82005

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
terryjreedy added 3 commits August 16, 2019 00:58
@terryjreedy
bpo-37824: Properly handle user input warnings in IDLE shell.
eb87bcd
Cease turning SyntaxWarnings into SyntaxErrors. Print warnings
in the shell, not a possibly non-existent command line.
@terryjreedy
Revern warning_stream when Shell closes.
be17e41
@terryjreedy
Stop printing bogus prompt after warning.
54edc23
@terryjreedy terryjreedy added type-bug An unexpected behavior, bug, or error DO-NOT-MERGE needs backport to 3.7 labels Aug 16, 2019
@terryjreedy terryjreedy self-assigned this Aug 16, 2019
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Aug 16, 2019
@bedevere-bot bedevere-bot added the awaiting core review label Aug 16, 2019
terryjreedy added 9 commits August 26, 2019 02:42
@terryjreedy
Merge branch 'master' into warn
73aaf87
@terryjreedy
Merge remote-tracking branch 'origin/master' into warn
a82437d
# Conflicts:
#	Lib/idlelib/pyshell.py
@terryjreedy
Merge remote-tracking branch 'origin/master' into warn
12e292b
@terryjreedy
Adjust test to changed warning format.
0fade74
@terryjreedy
Merge remote-tracking branch 'origin/warn' into warn
d45b1e0
# Conflicts:
#	Lib/idlelib/pyshell.py
@terryjreedy
bpo-37309: Update IDLE NEWS.txt
8d4d9bb
@terryjreedy
Merge remote-tracking branch 'upstream/master'
83c713a
@terryjreedy
Merge remote-tracking branch 'upstream/master'
0ae61bc
@terryjreedy
Merge remote-tracking branch 'origin/master' into warn
b2ebe5c
# Conflicts:
#	Lib/idlelib/pyshell.py
@terryjreedy terryjreedy added the needs backport to 3.9 label May 25, 2020
@csabella
Show warnings once
a20cf7c
@terryjreedy

terryjreedy commented May 26, 2020

Copy link
Copy Markdown
Member Author

Thank you. I just fixed the merge conflict so I could get back to this. Will try to test soon.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

taleinat
taleinat reviewed May 26, 2020
View reviewed changes
Comment thread Lib/idlelib/pyshell.py
# self.write("Unsupported characters in input\n")
# return
# II.runsource() calls .runcode(), overridden below.
with warnings.catch_warnings():

@taleinat taleinat May 26, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@terryjreedy terryjreedy May 28, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@terryjreedy terryjreedy May 28, 2020

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
terryjreedy added 3 commits May 27, 2020 22:39
@terryjreedy
Merge remote-tracking branch 'upstream/master' into warn
497298c
@terryjreedy
Merge branch 'warn' of https://github.com/terryjreedy/cpython into warn
b72612a
@terryjreedy
Clean PyShell.runsource of unneeded assert and comments.
d5849ad
@terryjreedy

terryjreedy commented May 28, 2020

Copy link
Copy Markdown
Member Author

As for 'bug 2', warning printed before code (initial post): it does not look so bad now compared to alternatives. But the speculated reason is wrong. The same is true with multiple lines. But Bug 3: the warnings are printed with each return after the first, and there must be at least 2.

>>> 
Warning (from warnings module):
  File "<pyshell#7>", line 2
    print('\e')
DeprecationWarning: invalid escape sequence \e

Warning (from warnings module):
  File "<pyshell#7>", line 1
    if 0 is 0:
SyntaxWarning: "is" with a literal. Did you mean "=="?

Warning (from warnings module):
  File "<pyshell#8>", line 2
    print('\e')
DeprecationWarning: invalid escape sequence \e

Warning (from warnings module):
  File "<pyshell#8>", line 1
    if 0 is 0:
SyntaxWarning: "is" with a literal. Did you mean "=="?
if 0 is 0:
	print('\e')

	
\e
>>> 

So scratch what I said before. 'Once' must apply across Enters, and, I think, at least across inputs between restarts, if not the whole session.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv ambv removed needs backport to 3.7 labels May 4, 2021
@ambv ambv removed the needs backport to 3.9 label May 17, 2022
@ambv

ambv commented May 17, 2022

Copy link
Copy Markdown
Contributor

This missed the boat for inclusion in Python 3.9 which accepts security fixes only as of today.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
@terryjreedy terryjreedy changed the title bpo-37824: Properly handle user input warnings in IDLE shell. gh-82005: Properly handle user input warnings in IDLE shell. Dec 17, 2023
@serhiy-storchaka serhiy-storchaka mentioned this pull request Dec 17, 2023
IDLE: Handle Shell input SyntaxWarning & DeprecationWarning #82005
Open
@terryjreedy
Merge branch 'main' into warn
d250b71
@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@taleinat taleinat taleinat left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@terryjreedy terryjreedy

Labels

awaiting core review DO-NOT-MERGE stale Stale PR or inactive for long period of time. type-bug An unexpected behavior, bug, or error

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@terryjreedy @ambv @taleinat @the-knights-who-say-ni @ezio-melotti @bedevere-bot @csabella
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.