On Tue, Aug 19, 2008 at 11:19:12PM +0100, Chris Withers wrote: > However, how should I go about adapting an object to an interface where > there may or may not be an adapter registered?
obj = ISomething(otherobj, None) > The natural way would seem to be: > > obj = ISomething(otherobj,default=None) I like this version. It's much clearer. > ...but I seem to remember people finding reasons why implementing that > would never be possible. I think that was about making ISometing(foo, bar) do a multi-adapter lookup instead of the current semantics (using bar as the default). > From a use point of view, I'd only expect queryAdapter to consider > looking for a named adapter if I actually provide a name. If I provide > no name, it would seem logical to look up a non-named adapter. If > looking up a non-named adapter, it would make sense if the object > already provides the desired interfaces to just return the object. > > I'd love to see where this expectation is faulty... It's also what I expected, and Jim managed to convince me I was wrong. Well, almost. I still think there's a smell if something doesn't work the way people expect, even if it all seems very elegant after a long protracted explanation. FWIW, there's another difference between ISomething(foo) and getAdapter(foo, ISomething): class SampleObject(object): def __conform__(self, iface): if iface is ISomething: return self.something obj = SampleObject() obj.something = SomethingElse() ISomething(obj) will return obj.something. getAdapter(obj, ISomething) will raise a ComponentLookupError. Marius Gedminas -- <Corsac> yeah, i'm reading the answers, currently <Corsac> but what I see is that there is no real procedure to rebuild initfs <Corsac> the common way seems to use a loop device with a jffs2 filesystem, put original files there, and add other files, then umount, flash and pray <dwd> Corsac: You forgot "ritual sacrifice of a medium sized rodent". Without that, it'll never work. <zuh> And if it doesn't work the first time, re-adjust towel ordering in the restroom and try again -- #maemo
signature.asc
Description: Digital signature
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )