[Types-sig] QueryProtocol
Clark C. Evans
cce@clarkevans.com
Sun, 25 Mar 2001 00:37:51 -0500 (EST)
On Sat, 24 Mar 2001, Michel Pelletier wrote:
> > # first check to see if object has the exact protocol
> > > if type(protocol) is types.InterfaceType and \
> > > instance(obj,protocol): return obj
> > if type(obj) is types.InstanceType and \
> > obj.__class__ is protocol: return obj
> > if type(obj) is protocol: return obj
> >
> > # procedure to execute on success
> > def succeed(retval,obj,protocol,can_wrap):
> > > if type(protocol) is types.InterfaceType:
> > > if not instance(retval,protocol):
> > > raise "Bad __adapt__ or __prodapt__!"
> > if can_wrap: return retval
> > return obj
>
> Actually, you would say:
>
> if implements(obj, protocol): return obj
>
> An object that implements an interface is not an instance of that
> interface, so 'instance' would fail (did you mean 'isinstance'?).
Typo. Darn fingers, typing in wrong words on me.
Thank you for pointing it out.
;) Clark