On 22 July 2011 13:32, Joshua Immanuel <j...@hipro.co.in> wrote:
> Hello,
>
> On Fri, 2011-07-22 at 13:41 +0200, Jacob Holm wrote:
>> On 2011-07-22 13:26, Brian Sutherland wrote:
>> > This would be my first guess:
>> >
>> >     class INode(Interface):
>> >         pass
>> >
>> >     INode.parent = Object(
>> >             title=u"Parent node",
>> >             schema=INode
>> >             )
>> >
>> >     INode.children = List(
>> >             title=u'Child nodes',
>> >             value_type=Object(schema=INode)
>> >             )
>> >
>>
>
> The method suggested by Brian works without any issues. :)

No, there are issues. Take this example:

>>> class ITest(Interface):
...  title = schema.TextLine()
...
>>> ITest.names
<bound method InterfaceClass.names of <InterfaceClass __main__.ITest>>
>>> ITest.names()
['title']
>>> ITest.description = schema.Text()
>>> ITest.names()
['title']

The fields on an interface are not stored as attributes, but are
accessible using item access, e.g: ITest['title']. You cannot assign
that way though:

>>> ITest['description'] = schema.TextLine()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: 'InterfaceClass' object does not support item assignment

Adding to an interface requires messing with the
'_InterfaceClass__attrs' attribute of the dictionary and is
discouraged.

Laurence
_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )

Reply via email to