Terry J. Reedy added the comment:

Some background context before I comment on the patch: Printing warnings to a 
console is a flawed idea. It does not work on Windows when Idle is run with 
pythonw and there is no console to write to. This is the normal case on Windows 
and, I suspect, the majority of all Idle uses across all systems. The attempt 
to write (to sys.__stderr__ == None) raises OSError, which shuts Idle down 
unless caught. (Thomas experiences exactly this when Python attempted to write 
the traceback.)  Either way, there is no message to be seen. Even when writing 
to console is successful, the message will often be hidden by Idle windows. 
Maybe it will be seen later, but  possibly not. 

Idle is a gui program and should not assume a text console. We should use tk 
messages boxes instead. Or perhaps put warnings in an Output Window (either 
instead, or in addition). Or put an error.log in .idlerc/ (this would be 'in 
addition'. Or also write to console when there is one, but not as the only 
message delivery system.

For problems in config files, I think we should, if possible, fix, rename, or 
delete the file. In any case, make it so the same warning will not appear next 
time Idle it is started. If we do anything, the warning message should say what 
was done.

There are 6 places in configHandler with code like the following:
            if  <config problem>:
                # do default, print warning
                warning=...
                try:
                    sys.stderr.write(warning)
                except OSError:
                    pass

(In one of the 6, Idle exits instead of catching OSError; there is another 
issue to fix this.)  These blocks mix together situation-specific message 
creation with a common and flawed delivery system. The latter should be 
factored out and fixed in a separate function at the top of the file (which I 
can write a first version of).

def config_warn(message): ... 

The problem with the patch is that it does not follow existing configHandler 
code. First, it stores errors and shuffles them off to be dealt with in 
PyShell. They should instead be immediately dealt with where detected. Second, 
it uses idle_showwarning to format and emit the warning.  Formatting with 
idle_formatwarning is ok, but idle_showwarning is designed specifically for the 
shell, ending warnings with the shell prompt '>>> '. It also has the flaw of 
the code above.  By default, it sends messages to an often non_existent 
sys.__stderr__. The patch should use the new config_warn function.

I will look at the new tests later.

When GSOC is done, I want to look as Tal's extension config dialog. That should 
reduce errors from users hand-editing config-extensions. Saimadhav has also 
done some work on key validation that needs to be applied to configHandler and 
configDialog. That should reduce key errors a bit.

----------

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

Reply via email to