[Types-sig] Interfaces API: a concrete contact point

Paul Prescod paulp@ActiveState.com
Thu, 15 Mar 2001 22:02:50 -0800

Samuele Pedroni wrote:
> Hi.
> If we  really aim for having just interfaces (still not convinced about
> that <wink>)  IMHO a possible solution is to define their check this way:
> if the input to check against an interface IFace is an instance foo, we
> check if foo has an '__implements__'
> attribute in that case we test IFace.isImplementedBy(foo), otherwise we
> check if foo has all the required signatures :).

That's exactly what my code already implements:

    # if the object CLAIMS to support an interface, we believe it
     if _findInterface(val, iface):
        return 1    

    # if the object LOOKS like it supports an interface,  good 'nuff
        return iface.__check__(val)

findInterface recursively looks for this interface or any of its base
interfaces in the list of values

> Then eventually
> "class A implements IFace" should check at definition time if A has all
> the needed signatures,
> raising warnings for the missing signatures still allowing that way
> incremental coding.


Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook