Re: Trellis: setting @maintain attributes / initialization rollback

"Sergey Schetinin" <[email protected]>
Newsgroups gmane.comp.python.peak
Message-ID <[email protected]>
Works well with my tests. Thanks!

Regarding corner cases, for example the TempConverter from README can
be initialized with TempConverter(F=0, C=0), which breaks the data
integrity. Such use of maintain rules would make sense in some cases
and one can add another maintain rule to check .was_set for both cells
to control such cases, but I thought I'd mention it anyway, because it
seems somewhat relevant.


On Thu, Oct 9, 2008 at 00:52, Phillip J. Eby <pje-Wh6+Hckhi6HFNGf7iClzIwC/[email protected]> wrote:
> At 11:47 PM 10/8/2008 +0300, Sergey Schetinin wrote:
>>
>> Consider this example:
>>
>> class C(Component):
>>    @maintain(optional=True)
>>    def calc(self):
>>        return 0
>>
>>    @maintain
>>    def getx(self):
>>        print 'get'
>>        self.calc
>>
>>    @maintain
>>    def set(self):
>>        print 'set'
>>        self.calc = 1
>>
>> c = C()
>>
>> Depending on luck (order of hashes of get / set attr names I suppose)
>> we either get InputConflict or not.
>> If the get rule runs first, set rule is a conflict because the Cell is
>> set by the calc rule.
>> If set gets to run first, there's no conflict because calc rule
>> doesn't need to run.
>
> Actually, in that last case, the calc rule does need to run -- and does.
>  It's just that its output is discarded, and not considered a conflict.
>
>
>> Is it possible to have calc / get rules rollback even when set runs last?
>
> Hm.  I suppose.  This seems to work (line 143 of trellis.py):
>
>            if self._set_by is not ctrl.current_listener and self._set_by is
> not self:
>
> It doesn't break any of the existing tests, and adding a test for the above
> (forcing the order using an __init__ method) seems to work:
>
>    def testResetCalcValue(self):
>        class C(trellis.Component):
>
>            trellis.maintain(optional=True)
>            def calc(self):
>                return 0
>
>            trellis.maintain()
>            def getx(self):
>                print 'get'
>                self.calc
>
>            trellis.maintain()
>            def set(self):
>                print 'set'
>                self.calc = 1
>
>            def __init__(self):
>                self.getx
>                self.set
>
>        c = C()
>
>
> That is, it generates an InputConflict without the change, and prints "get",
> "set", "get" with the change.
>
> I am a little suspicious of this, even though it *seems* correct.  Mainly I
> worry a little about certain corner cases for initialization, but feel free
> to try the patch above for now.  I want to think about this a bit more
> before I officially support it.
>
> I agree, however, that it *should* be supported, because it's an order
> dependency of precisely the sort that the trellis should make impossible.  I
> just want to make sure it covers all the bases, and may need to think of
> some other test scenarios.
>
>



-- 
Best Regards,
Sergey Schetinin

http://s3bk.com/ -- S3 Backup
http://word-to-html.com/ -- Word to HTML Converter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.