[Grok-dev] Can't get grok.Annotations working

Paul Wilson paulalexwilson at gmail.com
Sun May 17 19:56:52 EDT 2009


2009/5/17 Paul Wilson <paulalexwilson at gmail.com>:
> Hi,
>
> I've been playing with grok.Annotations and can't seem to get them working.
>
> Taking the example from the docs:
> http://grok.zope.org/doc/current/reference/components.html#grok-annotation
>
> """
> Test file for annotations.
> """
> import grok
> from zope import interface
>
> class Mammoth(grok.Model):
>     pass
>
> class IBranding(interface.Interface):
>     unique = interface.Attribute("Brands")
>
> class Branding(grok.Annotation):
>     grok.implements(IBranding)
>     unique = 0
>
> I've had to modify the example because of a bug in the documentation.
>
>>>> import grok
>>>> grok.testing.grok('annotations_test')
>>>> from annotations_test import *
>>>> manfred = Mammoth()
>>>> mumbles = Mammoth()
>>>> livestock1 = IBranding(manfred)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib/python2.5/site-packages/zope.component-3.5.1-py2.5.egg/zope/component/_api.py",
> line 193, in adapter_hook
>     return sitemanager.queryAdapter(object, interface, name, default)
>   File "/usr/lib/python2.5/site-packages/zope.component-3.5.1-py2.5.egg/zope/component/registry.py",
> line 207, in queryAdapter
>     return self.adapters.queryAdapter(object, interface, name, default)
>   File "/usr/lib/python2.5/site-packages/grok-1.0b1dev-py2.5.egg/grok/meta.py",
> line 400, in getAnnotation
>     annotations = IAnnotations(context)
> TypeError: ('Could not adapt', <annotations_test.Mammoth object at
> 0x8d0bb2c>, <InterfaceClass zope.annotation.interfaces.IAnnotations>)

I have a look at the doctests and it seems that if I include the following:

>>> import zope.component
>>> from zope.annotation.attribute import AttributeAnnotations
>>> zope.component.provideAdapter(AttributeAnnotations)

then it works and my tests pass! Can anyone explain this requirement?
Is it required in the code or just as setup for testing?

Thanks,
Paul


More information about the Grok-dev mailing list