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

Paul Wilson paulalexwilson at gmail.com
Sun May 17 06:52:46 EDT 2009


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

This is the exact same exception that I get when using
grok.Annotations in my application (exercised by a doctest).

I know that in Zope 3 you have to do:

<include package="zope.app.annotation" />

...otherwise you get the same issue.

Any ideas what I'm doing wrong?

Thanks,
Paul


More information about the Grok-dev mailing list