[Types-sig] File Protocol Proposal
Wed, 14 Mar 2001 09:06:39 -0700
From: "Paul Prescod" <paulp@ActiveState.com>
> Writefile objects will be required only to have a .write() method.
> Readfile objects will be required only to have a .read([size]) method.
This sounds good. For reasons that I'll describe below though it might be
better for them to have different names. perhaps BasicWritefile and
> Users will be strongly encouraged to inherit from base classes that
> define other methods (e.g. readlines) in terms of the required method.
> class UserReadFile:
[A class that implements all file read methods in terms of just read]
This seems like an excellent idea! I'll see if I can come up with an
equivalent for readable and writable sequences.
Here's a couple of obeservations in no particular order:
Again I don't like the name UserReadFile. I think it suggests a false
parallel with UserList and UserDict. Those exist in order to subclass the
builtin list and dictionary classes, the above class has an entirely
If we are going to have a baseclass that users will be encouraged to inherit
from when defining there own file-like object, it should be possible to
require it in a type declararion. I'd suggest we use ReadFile (ReadableFile,
FileReader?) for the wide interface and BasicReadFile for the narrow
It's tempting to overload the above class to allow it act as a wrapper for a
basic readfile. So that I can use UserReadFile(aBasicReadFile) to get a full
featured ReadFile. I think that would just be a matter of adding an __init__
method. I'm not positive this would be a good idea, but I believe that this
is what would need to be added:
def __init__(self, wrapped=None):
if wrapped is not None:
self.read = wrapped.read
One an unrelated note, I didn't like the idea of using & and | when someone
else mentioned, since it seemed to be leading down the road to static typing
(a road to nowhere IOW). However, if typecheck objects inherited from a
common base class it would be pretty easy to implement in terms of magic
methods. This would mean that "TypeA | TypeB | TypeC" would mean then same
as what I originally called CompositeOf(TypeA, TypeB, TypeC).