[PEAK] Trellis on_commit and Performers

Phillip J. Eby pje at telecommunity.com
Mon Oct 6 10:12:29 EDT 2008


At 11:10 AM 10/6/2008 +0300, Sergey Schetinin wrote:
> > Something is odd with them though. Following test prints 
> "maintain" three times.
> >
> > class Test(trellis.Component):
> >    @trellis.maintain
> >    def value(self):
> >        print 'maintain'
> >
> >    @value.connector
> >    def _watch(self, sensor):
> >       pass
> >
> >    @value.disconnector
> >    def _unwatch(self, sensor, key):
> >        pass
> >
> >
> > t = Test()
>
>Found a reason for this. In CellAttribute._hook_method it says:
>
>         if func is not None:
>             setattr(self, methodname, func)
>             return self
>
>Certainly it has to return func instead. Otherwise Test ends up with
>three identical items in CellFactories for each of value, _watch and
>_unwatch.

It does that to handle this case:

     @value.connector
     def value(self, sensor):
         ...

But it is clearly being over-aggressive.  I've fixed this to do more 
checking (ala the callback version), and added full test coverage for 
all possible calling scenarios.

The fix is checked in now, but you can also work around it by using 
@value.connector() and @value.disconnector() instead (note the () on 
the ends) or by naming the methods the same as the @maintain rule.




More information about the PEAK mailing list