New submission from Alexander Konovalenko:

Two pieces of the documentation for io.IOBase seem to contradict each other:

At http://docs.python.org/library/io.html#io.IOBase:
"Note that calling any method (even inquiries) on a closed stream is undefined. 
Implementations may raise IOError in this case."

At http://docs.python.org/library/io.html#io.IOBase.close:
"Once the file is closed, any operation on the file (e.g. reading or writing) 
will raise a ValueError."

Perhaps the confusion arises in part because it is not clear when a requirement 
for all IOBase implementations is documented and when the docs merely describe 
the default behavior of IOBase that implementations are free to override.

Those passages are inconsistent on two points:

1) IOError and ValueError are not subclasses one of another. So what should we 
expect an IOBase implementation to raise?

2) Undefined behavior means literally anything can happen. Technically, that 
means calling read() or readable() on a closed file (or other kind of stream) 
could wreak havoc in a totally unrelated part of the system or segfault the 
Python interpreter. That is definitely a thing to carefully avoid in any 
production systems.

On the other hand, raising an exception, even if we don't know in advance 
whether it will be ValueError or IOError, is pretty much defined behavior. An 
exception is easy to deal with and to contain inside a module.

So please clarify how dangerous it actually is to access an IOBase stream after 
it has been closed.

----------
assignee: docs@python
components: Documentation
messages: 169660
nosy: alexkon, docs@python
priority: normal
severity: normal
status: open
title: Ambiguity with regard to the effect of accessing a closed IOBase instance
versions: Python 2.7

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

Reply via email to