[docs] [issue21763] Clarify requirements for file-like objects
R. David Murray
report at bugs.python.org
Tue Jun 17 22:28:20 CEST 2014
R. David Murray added the comment:
Well, but we think it's pretty clear. The glossary entry says file object interfaces are defined by the classes in the io module. As do the io module docs. Perhaps the first sentence of the io docs could be modified to strengthen that (but it already does link to the glossary entry which is explicit that the io module defines the interfaces).
On the other hand, your statement that "few or no other assumptions are made" is, while not accurate, not *wrong*, in the following sense: *if* a standard library module depends on file attributes and methods, then it expects them to conform to the io module interfaces. If it does not depend on a particular part of the API, then a duck type class doesn't actually have to implement that API in order to work with that standard library module. Of course, we might change what elements of the file API are depended on, but hopefully we only do that kind of change in a feature release. I'm sure we have made such changes while fixing bugs, though, so if you want to be *sure* of forward compatibility, you should indeed implement the full io-specified interface in your file-like class. Which is one reason the ABCs provide default implementations for most of the methods. It makes it really easy to build a future-proofed duck type.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21763>
_______________________________________
More information about the docs
mailing list