Marius Gedminas wrote:
> 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)

Ah, okay. Now I remember. I've often wanted to be able to do:

obj = ISomething(obj1,0bj2,0-bj3) to get a multiadapter.
Now that I can see the above, I know why that's not possible.

So what you describe above actually works currently?

>> The natural way would seem to be:
>> obj = ISomething(otherobj,default=None)
> I like this version.  It's much clearer.

What's the default parameter currently called then?

> I think that was about making ISometing(foo, bar) do a multi-adapter
> lookup instead of the current semantics (using bar as the default).

indeed, correct you are :-)

> It's also what I expected, and Jim managed to convince me I was wrong.

Fine, now try and convince me ;-)

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

Nothing that requires a protracted explanation is elegant.

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

I have no idea what __conform__ is, so I guess I don't mind too much ;-)


Simplistix - Content Management, Zope & Python Consulting
Zope-Dev maillist  -
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to