[issue22298] Lib/warnings.py _show_warning does not protect against being called with a file like object which is closed

2016-11-25 Thread Julius Lehmann-Richter

Julius Lehmann-Richter added the comment:

Hey Wolfgang,

thank you for the clarification.

I would never write such code of course, I stumbled across this with a 
third-party program.

I understand your point of view and I actually agree. I would not have even 
opened this report if it had not been for that comment.

If the error is still reproducable in the software I will open a bug with them 
instead and tell them to please fix it :P

As far as I am concerned this is not a bug (any more)

Cheers Julius

--

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



[issue22298] Lib/warnings.py _show_warning does not protect against being called with a file like object which is closed

2016-11-25 Thread Julius Lehmann-Richter

Julius Lehmann-Richter added the comment:

Hey Wolfgang,

thank you for looking into this old one again ;)

The argument you are making does not answer the original bug report though as 
far as I can see.

My initial problem was not the AttributeError about the missing write but a 
ValueError (I/O operation on closed file).

Also this seems to have started a discussion about good programming practice 
between Terry and Antoine, my initial argument though was that, when you are 
catching an IOError for an invalid file, why not catch the ValueError for the 
closed file (since a closed file is surely not a valid target for a write 
operation).

I would really like to be educated on this if I am missing something, why does 
the argument for not silencing errors and expecting good programming practice 
apply to the ValueError of a closed standard error which has not been set to 
None but not to an IOError of a passed in file object?

Cheers Julius

--

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



[issue22298] Lib/warnings.py _show_warning does not protect against being called with a file like object which is closed

2014-08-29 Thread Julius Lehmann-Richter

New submission from Julius Lehmann-Richter:

In Lib/warnings.py the _show_warning function catches IOError with the 
commented intention to ward against an invalid file:

def _show_warning(message, category, filename, lineno, file=None, line=None):
Hook to write a warning to a file; replace if you like.
if file is None:
file = sys.stderr
try:
file.write(formatwarning(message, category, filename, lineno, line))
except IOError:
pass # the file (probably stderr) is invalid - this warning gets lost.

If for some reason the file like object, and in the default case stderr, is 
closed, a calling program is faced with a ValueError, which is not being caught.

It seems to me, and correct me if I am wrong, that a file object which has been 
closed is a case of an invalid file and that the warning subsystem should in 
that case behave in the same manner as in the case of the IOError.

This behavior is the same for python 3.2 with the function renamed to 
showwarning and can be reproduced with for example

from sys import stderr  
from warnings import warn
 
stderr.close()
try:
warn(foo)
except ValueError as e:
print(e)

--
components: Library (Lib)
messages: 226058
nosy: Julius.Lehmann-Richter
priority: normal
severity: normal
status: open
title: Lib/warnings.py _show_warning does not protect against being called with 
a file like object which is closed
type: behavior
versions: Python 2.7, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22298
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com