Yet Another PEP: Query Protocol Interface or __query__
Clark C. Evans
cce at clarkevans.com
Mon Mar 26 00:09:34 CEST 2001
On Sun, 25 Mar 2001, Magnus Lie Hetland wrote:
> "Clark C. Evans" <cce at clarkevans.com> wrote in message:
> > This proposal puts forth a light-weight explicit mechanism
> > for the adaptation (including verification) of an object to
> > a context where a specific type, class, interface, or other
> > protocol is expected.
> I like the generality here -- nice PEP overall, IMO :)
I've asked for a location on source forge for it.
After talking with a few people, I think it would be
appropriate to field test it for a while; if the
component falls into a resonable amount of usage
then I'll ask for it to be built-in. This will also
allow for any changes to be made before it is
> > To enable the first case listed in the requirements,
> > the adapt function first checks to see if the objects
> > type or the objects class are identical to the protocol.
> > If so, then the adapt function returns the object directly
> > without further ado.
> Hm. So in some cases the protocol object is merely an example
> (prototype) of an object satisfying the protocol, and in other
> cases it represents the protocol itself (with __prodapt__ etc)?
Sorry if this is unclear, a protocol is a TypeType or a TypeClass.
If an __adapt__ method wants to use another python type for
a protocol, then the framework doesn't care.
> In that case, one could perhaps use adapt(obj,SomeClass), and
> the function would check if obj was an instance of SomeClass;
> it would *not* check whether SomeClass and obj were instances
> of the *same* class (which seems semantically weird in this
> context to me...)
> *Or*, the intransitive version of __adapt__ could be
> called __conform__, which is indeed intransitive. Then the
> transitive version could be called __adjust__ or __adapt__ or
> whatever. I think that gets my vote:
> __conform__ - method in an object which can conform to
> a protocol
> __adapt__ - method in a protocol used to adapt an
> object to it
Very Nice. Much better than __prodapt__, which is almost a joke.
More information about the Python-list