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

Barry A. Warsaw barry@zope.com
Mon, 15 Jul 2002 10:32:18 -0400


>>>>> "A" == Aahz  <aahz@pythoncraft.com> writes:

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

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

    A> Can instances of C be used where a file object is expected?

Maybe <wink>.

That's why you tend to see things described like: "argument f must
have a write() method that accepts a string."  WIBNI we could define a
protocol/interface/thingie that encapsulated that requirement?  I'd
even be happy to start out with no officially blessed interfaces, to
give time to see what cream rises to the top.  Zope's Interface and
component model stuff is a good way to get some real experience with
using these concepts in Python.

-Barry