[Zope3-Users] recursive constraints
Gary Poster
gary at zope.com
Mon Aug 22 10:09:01 EDT 2005
On Aug 22, 2005, at 9:00 AM, Markus Leist wrote:
> Hello,
>
> there are a few (older) mails about "recursive constraints" in Zope3.
> I wasn't able to find a solution for this small problem:
>
> in interface.py:
> ------------------------
> class IIkGroup(IIkSClass):
> def __setitem__(name, object):
> """Add a IIkGroup object."""
> __setitem__.precondition = ItemTypePrecondition( IIkInterface)
> [...]
> ------------------------
>
> only Instances of IkInterface are allowed to add, ok so far.
>
> Now it should be possible to add an Instance of IkGroup (on itself)?
> "... ItemTypePrecondition( IIkGroup, IIkInterface) ..." is a stupid
> idea, because
> pathon don't know IIkGroup() at this time.
>
> I don't wont to implement an "IContained"-mechanism and
> setTaggedValue... seems to be obsolete - is this possible?
Hi Markus. Yes, it is somewhat ugly to do, but possible. If you
look at how the zope.app.container constraint stuff works you should
be able to figure how to do it. Essentially, even though we mostly
want interfaces to be immutable, they are not. If you mutate them
right after you construct them--adding a 'precondition' attribute to
__setitem__, for instance--you should be able to swallow your
distaste and get the behavior you want. :-)
Gary
More information about the Zope3-users
mailing list