Re: [Zope3-dev] tagged value handling inconsequent for interface methods and attributes and interfaces themself
On Tuesday 01 November 2005 04:27, Grégoire Weber wrote: 2005/10/24, Stephan Richter [EMAIL PROTECTED]: class IFoo(zope.interface.Interface): attr = zope.interface.Attribute('doc string') ITaggedValues(attr).someVariable = value Any comments before I spend time writing this up? The drawback*) of this is that the adapter registry has to be in place. *) Mostly a drawback if you only use ``zope.interface`` No it does not need to necessarily, because the __conform__ method is called before a standard adapter lookup is made. Also, for those type of scenarios we could have a custom adapter registry. Luckily adapter registries are implemented in zope.interface.adapter, so no external packages would be necessary. Regards, Stephan -- Stephan Richter CBU Physics Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training --- -- Stephan Richter CBU Physics Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] tagged value handling inconsequent for interface methods and attributes and interfaces themself
Just for the notes: I first favoured something like this: class IFoo(zope.interface.Interface): attr = zope.interface.Attribute('doc string') attr.someVariable = value but this can't work if ``attr`` is defined in ``IBar`` and setting a tagged value is done in ``IFoo`` (which is inheriting from ``IBar``) like this: class IBar(zope.interface.Interface): attr = zope.interface.Attribute('doc string') class IFoo(IBar): attr.someVariable = value # NameError 2005/10/24, Stephan Richter [EMAIL PROTECTED]: class IFoo(zope.interface.Interface): attr = zope.interface.Attribute('doc string') ITaggedValues(attr).someVariable = value Any comments before I spend time writing this up? The drawback*) of this is that the adapter registry has to be in place. *) Mostly a drawback if you only use ``zope.interface`` Gregoire ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] tagged value handling inconsequent for interface methods and attributes and interfaces themself
On Wednesday 19 October 2005 05:51, Grégoire Weber wrote: 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. I plan to make a proposal that would allow the following: import zope.interface class IFoo(zope.interface.Interface): attr = zope.interface.Attribute('doc string') def method(): doc string interfaceTags = zope.interface.interfaces.ITaggedValues(IFoo) interfaceTags.someVariable = value attributeTags = zope.interface.interfaces.ITaggedValues(IFoo['attr']) attributeTags.someVariable = value methodTags = zope.interface.interfaces.ITaggedValues(IFoo['method']) methodTags.someVariable = value Alternatively, I would like to try the following as well: from zope.interface.interfaces import ITaggedValue class IFoo(zope.interface.Interface): attr = zope.interface.Attribute('doc string') ITaggedValues(attr).someVariable = value Any comments before I spend time writing this up? Regards, Stephan -- Stephan Richter CBU Physics Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Interface-dev] Re: [Zope3-dev] tagged value handling inconsequent for interface methods and attributes and interfaces themself
On Monday 24 October 2005 16:44, Jim Fulton wrote: Any comments before I spend time writing this up? This won't work for tags whos keys are not python identifiers. I'd like to encourage people to use ids (dotted names or urls) for tags. Okay, in this case I'll implement a mapping interface, instead an attribute one. Is that the change you were hinting at? Regards, Stephan -- Stephan Richter CBU Physics Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
[Zope3-dev] tagged value handling inconsequent for interface methods and attributes and interfaces themself
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'} ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] tagged value handling inconsequent for interface methods and attributes and interfaces themself
On Wednesday 19 October 2005 05:51, Grégoire Weber wrote: 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: I agree. Note that there is also a zope-interface mailing list. in the interface definition: meth.tag = 'tagged' # interrestingly ``meth.setTaggedValue`` doesn't work attr.tag = 'tagged' # have to use ``attr.setTaggedValue('tag', 'tagged')`` currently I think that setTaggedValue() should be the only thing that works, ever. on module level: IGaga.tag = 'tagged' # have to use ``IGaga.setTaggedValue('tag', 'tagged')`` currently This should definitely fail, using setTaggedValue() is again the right choice. See code below with traces. I didn't dig deep enough into the interface implementation to find out why. I may try. Any hints? I think you should have no problems finding support for this fix, so please feel free to fix it. Regards, Stephan -- Stephan Richter CBU Physics Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] tagged value handling inconsequent for interface methods and attributes and interfaces themself
Stephan Richter wrote: On Wednesday 19 October 2005 05:51, Grégoire Weber wrote: 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: I agree. Note that there is also a zope-interface mailing list. in the interface definition: meth.tag = 'tagged' # interrestingly ``meth.setTaggedValue`` doesn't work attr.tag = 'tagged' # have to use ``attr.setTaggedValue('tag', 'tagged')`` currently I think that setTaggedValue() should be the only thing that works, ever. on module level: IGaga.tag = 'tagged' # have to use ``IGaga.setTaggedValue('tag', 'tagged')`` currently This should definitely fail, using setTaggedValue() is again the right choice. See code below with traces. I didn't dig deep enough into the interface implementation to find out why. I may try. Any hints? I think you should have no problems finding support for this fix, so please feel free to fix it. +1 on all above. :) Jim -- Jim Fulton mailto:[EMAIL PROTECTED] Python Powered! CTO (540) 361-1714http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com