I got this idea, after I worked with Qt. It use object property, rather then variable:
from types import FunctionType
class MyObject:
def __init__(self,name):
self.name= name
self._a_f=None
self._a=None
@property
def a(self):
if self._a_f is not None:
self._a= self._a_f()
return self._a
@a.setter
def a(self,v):
if type(v) is FunctionType:
self._a_f=v
else:
self._a_f=None
self._a=v
o1,o2,o3=map(MyObject,'abc')
o1.a = lambda: o2.a + o3.a
o2.a = lambda: o3.a * 2
o3.a = 10
print( o1.a ) #print 30
o2.a = o1.a + o3.a #this will unbind o3.a from o2.a, setting it to 40
print( o1.a ) #print 50
But what if you want to know when o1.a
changed? That's what my first desire was, but implementation is hard. Even if it probably answer other question, here have some example:
class MyObject(metaclass=HaveBindableProperties):
a= BindableProperty()
someOther= BindableProperty()
o1,o2,o3=map(MyObject,'abc')
o1.a = lambda: o2.a + o3.a
o2.a = lambda: o3.a * 2
@o1.subscribe_a
def printa():
print( o1.a )
o3.a = 1 #prints 3
printa.unsubscribe() #to remove subscribtion