[Zope-dev] adapting to None
Chris Withers
chris at simplistix.co.uk
Fri Dec 12 21:17:25 EST 2008
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?
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the Zope-Dev
mailing list