Terry J. Reedy <tjre...@udel.edu> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37824>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to