Chris Withers wrote at 2008-12-13 10:18 +0000:
>Dieter Maurer wrote:
>> I think that in some cases, it would be useful for an adapter factory
>> to say 'I cannot handle this case' and then the adapter lookup
>> is continued. Maybe, this is already supported?
>> Then, maybe, you can use it?
>
>That's exactly what returning None indicates...
>
>>> def some_adapter(obj):
>>>   if something:
>>>     return None
>>>   return somethingelse
>> 
>> Your use case seems to abuse adaptation:
>> 
>>   Adaptation to an interface must always return an object which provides
>>   the interface.
>>   "None", by default, only provides very few interfaces 
>
>...indeed, however, I really do want to return None here.

Then, use something different from adaptation (as adaptation does
not fit your wishes).

I expect that your adapter factory can raise "ComponentLookupError"
when it cannot handle the adaptation and then the "default" argument
of the adapter lookup will take effect.

   adapter = IMyInterface(obj, None)
   if adapter is None:
      # adaptation impossible
      ....

   def adapter_factory(...):
      ...
      raise ComponentLookupError()



-- 
Dieter
_______________________________________________
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 )

Reply via email to