[Zope3-dev] Interface surprise

Guido van Rossum guido@python.org
Mon, 31 Mar 2003 10:12:14 -0500


> 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.

--Guido van Rossum (home page: http://www.python.org/~guido/)