Hi All,

I have a need to be able to adapting certain objects to None, eg:

def some_adapter(obj):
   if something:
     return None
   return somethingelse

This is tricky, since returning None from an adapter results in a TypeError.

I eventually came up with the idea of having a subclass of Interface do 
what I needed:

empty = object()

class IFieldType(Interface):
     def __call__(self,*args,**kw):
         r = Interface.__call__(*args,**kw)
         if r is empty:
             return None
         return r

I suspect this would work with the python implementation of Interface, 
but it certainly doesn't with the C implementation.

What am I doing wrong and how can I achieve what I'm after?



Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk
Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to