[Python-Dev] PEP 246, Object Adaptation (was Re: Single- vs. Multi-pass iterability)

Aahz aahz@pythoncraft.com
Mon, 15 Jul 2002 10:22:25 -0400


On Mon, Jul 15, 2002, Clark C . Evans wrote:
>
> My exposition was awful, sorry.   Perhaps a specific (albeit contrived)
> example would better reflect the intent.   Suppose that I have a iterator
> with one method, next().   Now suppose that I want a "mutable iterator",
> one which adds the change() method.   This is well and good, but the
> concept of something being mutable is quite othogonal to iteration and
> perhaps should have its own interface rather than using inheritance.
> So, what I'm asserting is that once the inheritance "feature" is 
> there... people use it even though other approaches are available.

On the whole, I'd say that Python is actually *less* prone to this
problem (because using an object doesn't generally require inheritance,
just protocol); in fact, it suffers from the obverse problem.  Consider
this:

    class C:
        def open(self, name, flags=None):
        def read(self):
        def write(self, value):
        def close(self):

Can instances of C be used where a file object is expected?
-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/