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 alexkon
Recipients alexkon, docs@python
Date 2012-09-01.18:33:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1346524424.76.0.407141547435.issue15840@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012-09-01 18:33:44alexkonsetrecipients: + alexkon, docs@python
2012-09-01 18:33:44alexkonsetmessageid: <1346524424.76.0.407141547435.issue15840@psf.upfronthosting.co.za>
2012-09-01 18:33:44alexkonlinkissue15840 messages
2012-09-01 18:33:42alexkoncreate