[Zope3-dev] Interface surprise

Shane Hathaway shane@zope.com
Mon, 31 Mar 2003 10:25:17 -0500


Guido van Rossum wrote:
>>I've been using the following idiom in Zope 2 to discover whether an 
>>object is an interface definition:
>>
>>
>>from Interface import Interface
>>
>>def isInterface(obj):
>>     return Interface.isImplementedBy(obj)
>>
>>
>>This idiom has a little surprise, though: any object that implements any 
>>interface also implements Interface.  Since the above function yields 
>>numerous false positives, I don't know the right way to detect whether 
>>an object is an Interface.
>>
>>As a side effect, lots of objects promise to implement getBases(), 
>>extends(), getDescriptionFor(), etc., but they don't.
>>
>>What should Zope 3 do to fix this?  Has anything been done already?
> 
> 
> Can't you use issubclass(obj, Interface) in Zope3?  Seems to work for
> me.

Maybe so.  Another thing that occurred to me after I sent the email is 
that maybe my function should be looking for "IInterface" instead of 
Interface, and that maybe Interface.isImplementedBy(foo) doesn't 
actually promise anything at all.

It makes sense, but it's still surprising at first.

Shane