This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Julius.Lehmann-Richter, brett.cannon, pitrou, terry.reedy
Date 2014-08-30.03:39:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1409369983.49.0.170407478529.issue22298@psf.upfronthosting.co.za>
In-reply-to
Content
If sys.stderr is set to None, then "if file is None: file = sys.stderr" will have no effect and 'file.write' raises "AttributeError: 'NoneType' object has no attribute 'write'" (actual quote).  Do you propose to catch that?  If not, it is not much of an improvement. Multiple people have reported on python-list that they are mystified by messages like this when they never used a None object as an argument.

I am sympathetic to not overlooking bugs.  However, a traceback is normally lost in this situation anyway.  If sys.stderr is closed, trying to write a ValueError traceback (or any other traceback) to stderr generates another ValueError.  Python apparently tries to write a double traceback to sys.__stderr__ as a backup (see below).  If that is also unusable (perhaps because it *is* sys.stderr), then the traceback disappears anyway.  This is what happens (on Windows, at least) with python started from either an icon or in Command Prompt.

>>> import sys; sys.stderr.close()
>>> from warnings import warn; warn('foo')
>>> sys.stderr is sys.__stderr__
True

When Idle starts an icon, the result is the same except that the user process is restarted.  Also, two streams are not the same; sys.__stderr__ is None.

If Idle is run with python from a console, there is still no message in the Idle shell but since sys.__stderr__ points back to the console, the double traceback appears there: first the warn ValueError, then 'while proccessing...', the traceback ValueError.  Idle replaces showwarning.  I believe it now only changes the formatting, but I could have it use sys.__stderr__ when not None to print the warning instead of or in addition to the tracebacks.

If the code above is placed in a file and run in batch mode, python quits with no output.

C:\Programs\Python34>python temop.py

C:\Programs\Python34>

When run from the idle editor running under pythonw, the user process does the same (exit without output).
History
Date User Action Args
2014-08-30 03:39:43terry.reedysetrecipients: + terry.reedy, brett.cannon, pitrou, Julius.Lehmann-Richter
2014-08-30 03:39:43terry.reedysetmessageid: <1409369983.49.0.170407478529.issue22298@psf.upfronthosting.co.za>
2014-08-30 03:39:43terry.reedylinkissue22298 messages
2014-08-30 03:39:42terry.reedycreate