PEP 245

Clark C. Evans cce at clarkevans.com
Wed Apr 4 23:07:45 EDT 2001


> Except that PEP 246 is meant to operate on anything at all,
> which happens to include the interfaces.

PEP 246 was originally called "QueryProtocol" motivated 
from "query interface", hence the section on the differences.
However, a wholesale "import from COM" just didn't make sense 
as Python is far more dynamic.  So, this PEP started life
by a question... "What would a pythonic query interface look like?"
The response thus far has been very positive.

Very shortly after the initial post, Paul Prescod pointed out
that it could work in reverse as well.  Thus, the bi-directional
aspect came into being.  Paul also pointed out that a registry
could also be added... but that may be biting off more than necessary.

So.  To answer your query, I think allowing anything to suffice 
in this role is a good thing, hence the flexible definition of
"protocol" given in the PEP.  Restricting this role to just 
interfaces would, IMHO, be unpythonic.

> PEP 246 does not guarantee the symmetric behavior, which I 
> think is required for going back and forth between object's
> interfaces. Although the PEP says that such behavior may be 
> added. (See PEP's text)

I'm just not a COM guru, and I don't know the advantages or 
disadvantages that come with this restriction.  Thus, I left
it as an open issue for those who really understand this
deep stuff...  I just want a standard way to adapt objects.

> But all in all, PEP 246 can be implemented in such  way that 
> it satisfies '__getinterfacereference__' requirements.  But 
> that needs to be the default behavior for '__adapt__'.

I did my best so that it is specified (and in fact implemented)
in such a way as to satisfy these requirements.  How did I 
fall short?

Oh yes, __getinterfacereference__ would really map to __conform__
as this is the place where the object can return an object conformant
to the protocol's requirements.  __adapt__ allows the protocol to
accept or wrap the object...
  
...

With this in mind, I actually like PEP 245 (Interfaces) as it is.
Adding a QueryInterface mechanism to it would just confuse issues.
Having an othognal adapt mechanism is better... besides, it could
be used as the "bridge" between the previous world of classes 
and types, and the new world of interfaces...  just make sure that
interfaces cna have an __adapt__ method!

Thanks for looking at this stuff deeply,

;) Clark






More information about the Python-list mailing list