Hi there,

I notice a pattern in code that uses annotations that looks like this:

class Foo(Persistent, Contained):

def getFoo(context):
    annotations = IAnnotations(context)
        return annotations[FOO_KEY]
    except KeyError:
        foo = Foo()
        annotations[FOO_KEY] = foo
        # to please security...
            foo, context, 'foo')
        return foo

# Convention to make adapter introspectable
getFoo.factory = Foo

If I'm doing this quite a bit, this looks like something that would be better expressed in a... new ZCML directive (..waiting for the crowd to start flinging stones).

For instance, one that looks like this:

<zope:annotation for="IBar" factory="Foo" />

where the factory actually points to whatever creates the real annotation (such as the Foo class in this case), not to the boilerplate to attach it to the proper object. The boilerplate would go away from my code, you could use the facility too without thought, and we'd all be happy. :)

What do people think?


Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to