-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
IDLE: Handle Shell input SyntaxWarning & DeprecationWarning #82005
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
Comments
DeprecationWarning at compile time is output multiple times to the stderr (on console from which IDLE was ran), but not to IDLE Shell window. For example, when enter '\e': $ ./python -m idlelib Warning (from warnings module):
File "<pyshell#0>", line 1
'\e'
DeprecationWarning: invalid escape sequence \e
>>>
Warning (from warnings module):
File "<pyshell#0>", line 1
'\e'
DeprecationWarning: invalid escape sequence \e
>>>
Warning (from warnings module):
File "<pyshell#0>", line 1
'\e'
DeprecationWarning: invalid escape sequence \e And when close IDLE, additional output is printed in 3.8+: >>> Exception ignored in: <idlelib.run.PseudoInputFile object at 0x7f9e3b4a15a0>
Traceback (most recent call last):
File "/home/serhiy/py/cpython/Lib/idlelib/run.py", line 488, in close
File "/home/serhiy/py/cpython/Lib/idlelib/pyshell.py", line 1019, in close
File "/home/serhiy/py/cpython/Lib/idlelib/editor.py", line 1058, in close
File "/home/serhiy/py/cpython/Lib/idlelib/outwin.py", line 94, in maybesave
File "/home/serhiy/py/cpython/Lib/idlelib/editor.py", line 991, in get_saved
AttributeError: 'NoneType' object has no attribute 'get_saved' |
None.get_saved is bpo-35623. I believe it is related to bpo-35379, where I requested your comment on what I found so far.
DeprecationWarning: invalid escape sequence \e
|
I am combining the trivial 'leave Shell input SyntaxWarnings alone (instead of making them SyntaxErrors)' part of bpo-34857 with this issue, 'print Shell input (and the very rare internal IDLE Warnings occurring after Shell exists) in Shell, and changing the title accordingly. The PR is a WIP with at least two bugs. Help wanted.
|
Il take a look at this. I've very recently gone through the relevant parts of the code and I should be able to figure it it efficiently. |
The triple (or double, see below) printing seems like a pure bug to be fixed. A fix could be a separate PR to be merged 'immediately'. But there is a complication with insertion location. My bug claim was based on a one line statement, where 'before' looks wrong and 'after', as in REPL, right. >>> <IDLE>
Warning (from warnings module): # Printed 3 times, 2 deleted.
File "<pyshell#0>", line 1
0 is 0
SyntaxWarning: "is" with a literal. Did you mean "=="?
0 is 0
True
>>> 0 is 0 # REPL
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
True But now consider a more realistic compound statement. >>> if 0 is 0: # REPL
... print('true')
...
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
true With IDLE, a warning is printed *before* the user enters a blank line to signal end of statement. >>>
Warning (from warnings module): # Only printed TWICE!.
File "<pyshell#2>", line 1
if 0 is 0:
SyntaxWarning: "is" with a literal. Did you mean "=="?
if 0 is 0:
print('true')
|< cursor location A user could edit the condition, add more to the suite, or hit return. In the latter 2 cases, the warnings are repeated. In this case, the insertion seems like the best that can be done. Perhaps the msg349845 comment about run.show_warnings collecting warnings for possible delayed display applies to pyshell.show_warnings. Or the warning could be put in a popup, though I do not especially like the idea of that. Or it could be logged to a separate Warnings window, and a red "Warning logged' flashed on the status bar. I suspect that this case is why a fake prompt was previously tacked on to the end of the warning, though I also suspect these complications are why shell input warnings were relegated to a possibly non-existent console (where the fake prompt is nonsense). Behavior is the same with '\e' and DeprecationWarning. This example further convinces me that multiline shell input should be isolated from both prompts and intermixed outputs. I plan to open that issue later today. |
I see none of this on latest master (0567786) on Windows 10. Can you specify on what OS and Python branch/version this happens? |
My first post described master at the time, when SyntaxWarnings were converted to SyntexErrors and shell input warnings, in particular, Deprecation warnings were sent to the console or nowhere. My third post describes the situation with the PR, where SyntaxWarnings are left as warnings and shell input warnings go to shell. An improvement, but still buggy. I just reconfirmed after updating, compiling Python, and checking out my 'warn' branch. |
Terry, I put this into debug and found the reason it's printing the warning three times. In
It also has this in the module docstring:
|
I added a commit to the PR to show warnings once. |
codeop._maybe_compile wraps each compile in try ... except SyntaxError. It can later reraise just once. I think it a bug that it is not similarly careful about SyntaxWarning and DeprecationWarning to only emit a particular warning just once. Cheryl, would you like to open a new issue and submit a patch? |
Thanks, Terry. I created bpo-40807 for the codeop warnings. |
To review: Serhiy reported 3 'IDLE' bugs: tripled DeprecationWarning (now joined by SyntaxWarning), printing to console (if available) instead of Shell, and an exit exception.
Additional issues, semi-independent. |
The new items can be new issues, with 6 maybe the highest priority. Currently For both Shell and Editor input, the Warning Line is not really needed. For Shell, the fake filename is not needed, nor is the line # and line if somehow otherwise marked. |
bpo-43151 asked about 'is <literal>' syntax warnings in REPL. Discussion noted that IDLE Shell does note print it for "x is 'a'" (known here) and that for "if x is 'a': print('executed')" there is a syntax error and no execution. The conversion to SyntaxError was supposedly fixed by PR-15500, but it appears that the patch for bpo-40807 introduced it into codeop._maybe_compile. msg386621 has summary and discussion. I need to add debug prints or breakpoints into _maybe_compile to understand it better, and maybe improve it. Before printing syntax warnings in Shell, I want to stop expanding them from 1 to 4 lines. We could just not import the replacement from run.py, but I think the default format could be improved even with 1 or 2 lines. |
Might want to special case running certain console commands in Shell, such as 'pip install'. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: