◐ Shell
reader mode source ↗
Skip to content

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

Open
terryjreedy wants to merge 17 commits into
python:mainfrom
terryjreedy:warn
Open

gh-82005: Properly handle user input warnings in IDLE shell.#15311
terryjreedy wants to merge 17 commits into
python:mainfrom
terryjreedy:warn

Conversation

@terryjreedy

@terryjreedy terryjreedy commented Aug 16, 2019

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.

Cease turning SyntaxWarnings into SyntaxErrors. Print warnings
in the shell, not a possibly non-existent command line.
@terryjreedy

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.

@terryjreedy

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.

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

@terryjreedy terryjreedy changed the title bpo-37824: Properly handle user input warnings in IDLE shell. Dec 17, 2023
@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.

@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

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

Development

Successfully merging this pull request may close these issues.

7 participants