79645825

Date: 2025-05-30 16:55:40
Score: 0.5
Natty:
Report link

Thanks for your inputs @juanpa.arrivillaga. If I understand you correctly, this will cause updates on all the Aggregator instances to be triggered for any Tracker instance update, not only for the grouped ones (which is what I want).

t1 = Tracker()
t2 = Tracker()
a1 = Aggregator([t1,t2])
t1.value = 32
t2.value = 55

t3 = Tracker()
t4 = Tracker()
a2 = Aggregator([t3,t4])
t3.value = 29 # will trigger updates on a1 and a2!
t4.value = 37 # # will trigger updates on a1 and a2!

The solution that worked for me was to do the following:

class Tracker():
    def __init__(self):
        self._value = None

    @property
    def value(self):
        return self._value

    @value.setter
    def value(self, value):
        self._value = value
        if hasattr(self,'aggregator_update') and callable(self.aggregator_update):
            self.aggregator_update()
class Aggregator():
    def __init__(self,trackers):
        self.trackers = trackers
        for t in self.trackers:
            t.aggregator_update = self.update
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Whitelisted phrase (-1): worked for me
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: im-not-you