[Zope3-dev] tagged value handling inconsequent for interface methods and attributes and interfaces themself

Grégoire Weber gregweblists at googlemail.com
Wed Oct 19 05:51:10 EDT 2005


Hi everybody,

while modeling the external API of an application I'd like to use the
tagged value feature of the interface implementation.

It seems to me that handling tagged values is implemented inconsequently.

It would be nice if tagging attributes and interfaces would look the
same as tagging methods:

in the interface definition:

    meth.tag = 'tagged' # interrestingly ``meth.setTaggedValue`` doesn't work
    attr.tag = 'tagged' # have to use ``attr.setTaggedValue('tag',
'tagged')`` currently

on module level:

    IGaga.tag = 'tagged' # have to use ``IGaga.setTaggedValue('tag',
'tagged')`` currently

See code below with traces.

I didn't dig deep enough into the interface implementation to find out
why. I may try. Any hints?

Gregoire

-------------------------- executable code ------------------------

from zope.interface import Interface, Attribute


# ---------------------------------------------------------------------
# testing tagged values for methods and attributes
# ---------------------------------------------------------------------

class IGaga(Interface):
    """
    """
    def meth():
        """A method
        """
    meth.tag = 'tagged value ``tag`` of a method'
    # this doesn't work
    #meth.setTaggedValue('tag2', 'tagged value ``tag2`` of a method')

    attr = Attribute(
        """An attribute
        """)
    attr.tag = 'tagged value ``tag`` of an attribute'
    attr.setTaggedValue('tag2', 'tagged value ``tag2`` of an attribute')

IGaga.tag = 'tagged value of an interface'
IGaga.setTaggedValue('tag2', 'tagged value ``tag2`` of an interface')

# tagged values of methods
print IGaga['meth'].getTaggedValue('tag')

# tagged values of attributes
try:
    print IGaga['attr'].getTaggedValue('tag')
except KeyError:
    print 'KeyError when trying to get tagged value ``tag`` of an attribute'
print IGaga['attr'].getTaggedValue('tag2')

# tagged values of interfaces
try:
    print IGaga.getTaggedValue('tag')
except KeyError:
    print 'KeyError when trying to get tagged value ``tag`` of an interface'
print IGaga.getTaggedValue('tag2')

"""Debugging session

Tagged value of a method
------------------------

> /path/to/trunk/checkout/src/zope/interface/interface.py(73)getTaggedValue()
-> return self.__tagged_values[tag]
(Pdb) l
 71         def getTaggedValue(self, tag):
 72             " Returns the value associated with 'tag'. "
 73  ->         return self.__tagged_values[tag]
 74
(Pdb) self
<zope.interface.interface.Method object at 0x4aa80c>
(Pdb) self.__dict__
{'required': (), 'kwargs': None, '_Element__tagged_values': {'tag':
'tagged value of a method'}, 'positional': (), 'varargs': None,
'interface': <InterfaceClass __main__.IGaga>, '__name__': 'meth',
'optional': {}, '__doc__': '\n        '}


Tagged value of an attribute
----------------------------

> /path/to/trunk/checkout/src/zope/interface/interface.py(73)getTaggedValue()
-> return self.__tagged_values[tag]
(Pdb) l
 71         def getTaggedValue(self, tag):
 72             " Returns the value associated with 'tag'. "
 73  ->         return self.__tagged_values[tag]
 74
(Pdb) self
<zope.interface.interface.Attribute object at 0x48ad6c>
(Pdb) self.__dict__
{'interface': <InterfaceClass __main__.IGaga>, '__name__': 'attr',
'_Element__tagged_values': {}, 'tag': 'tagged value of an attribute',
'__doc__': '\n        '}


Tagged value of an interface definition
---------------------------------------

> /path/to/trunk/checkout/src/zope/interface/interface.py(73)getTaggedValue()
-> return self.__tagged_values[tag]
(Pdb) l
 71         def getTaggedValue(self, tag):
 72             " Returns the value associated with 'tag'. "
 73  ->         return self.__tagged_values[tag]
 74
(Pdb) self
<InterfaceClass __main__.IGaga>
(Pdb) self.__dict__
{'_InterfaceClass__attrs': {'meth': <zope.interface.interface.Method
object at 0x4aa80c>, 'attr': <zope.interface.interface.Attribute
object at 0x48ad6c>}, '_v_repr': '<InterfaceClass __main__.IGaga>',
'__module__': '__main__', '__iro__': (<InterfaceClass __main__.IGaga>,
<InterfaceClass zope.interface.Interface>), '_implied':
{<InterfaceClass zope.interface.Interface>: (), <InterfaceClass
__main__.IGaga>: ()}, '_Element__tagged_values': {}, 'tag': 'tagged
value of an interface', '__sro__': (<InterfaceClass __main__.IGaga>,
<InterfaceClass zope.interface.Interface>), '__identifier__':
'__main__.IGaga', '_v_attrs': {'meth':
<zope.interface.interface.Method object at 0x4aa80c>}, '__bases__':
(<InterfaceClass zope.interface.Interface>,), '__name__': 'IGaga',
'dependents': <WeakKeyDictionary at 4763148>, '__doc__': '\n    '}

"""


More information about the Zope3-dev mailing list