Skip to content

Commit

Permalink
Make lazy implementation python3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
gyst committed May 26, 2017
1 parent 79b6015 commit 8d5e511
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/grokcore/annotation/lazy.py
Expand Up @@ -19,7 +19,7 @@
import zope.annotation.interfaces
import zope.cachedescriptors.property

from zope.interface import implements
from zope.interface import implementer
from zope.location import Location
from zope.annotation.interfaces import IAnnotations
from grokcore.annotation.interfaces import IAnnotationFactory
Expand Down Expand Up @@ -89,8 +89,8 @@ def _load(self, key, default):
return getattr(storage, key, default)


@implementer(IAnnotationFactory)
class LazyAnnotationFactory(object):
implements(IAnnotationFactory)

def __init__(self, factory, name):
self.factory = factory
Expand Down
22 changes: 11 additions & 11 deletions src/grokcore/annotation/tests/annotation/lazy.py
Expand Up @@ -9,14 +9,14 @@
its attributes:
>>> lazyannotation = ILazy(manfred)
>>> lazyannotation.lazy_attribute
u'lazily waiting for a value.'
>>> str(lazyannotation.lazy_attribute)
'lazily waiting for a value.'
Note how just "getting" the annotation attribute's default value (as no
explicit value has been set before for this attribute), does not create
a new annotation objects:
>>> print manfred.__dict__
>>> print(manfred.__dict__)
{}
If nothing was explicitly set before, we still can query for the annotation
Expand All @@ -29,37 +29,37 @@
actually do store a new annotation object:
>>> lazyannotation.lazy_attribute = u'We have a value!'
>>> print manfred.__dict__
>>> print(manfred.__dict__)
{'__annotations__': <...OOBTree object at ...>}
>>> print list(manfred.__dict__['__annotations__'].keys())
>>> print(list(manfred.__dict__['__annotations__'].keys()))
['lazy.annotation.custom.name']
Now the queryAnnotation will indeed return the annotations object:
>>> grok.queryAnnotation(manfred, ILazy)
<...Lazy object at ...>
>>> grok.queryAnnotation(manfred, ILazy).lazy_attribute
u'We have a value!'
>>> str(grok.queryAnnotation(manfred, ILazy).lazy_attribute)
'We have a value!'
We can also delete the lazy annotation and the previously stored annotation
now is gone:
>>> grok.deleteAnnotation(manfred, ILazy)
True
>>> print manfred.__dict__
>>> print(manfred.__dict__)
{'__annotations__': <...OOBTree object at ...>}
>>> print list(manfred.__dict__['__annotations__'].keys())
>>> print(list(manfred.__dict__['__annotations__'].keys()))
[]
Note how the default schema value for the lazy attribute still "responds":
>>> lazyannotation = ILazy(manfred)
>>> lazyannotation.lazy_attribute
u'lazily waiting for a value.'
>>> str(lazyannotation.lazy_attribute)
'lazily waiting for a value.'
"""

Expand Down

0 comments on commit 8d5e511

Please sign in to comment.