I am developing a descriptor basing myself in the ideas of @property. What I would like is to understand if there is any way of easily extending the behavior of property beyond setting/getting.
The concrete example: I am communicating with a device, and would like to have a property that can set/get/update. In this way, when I set, I pass the new value to the device, and store it in the cache. When I get, I retrieve the cached value. When I update, the device is re-asked for the value. In this way, can avoid unnecessary communication with the device, unless explicitly triggered.
I don't know if there is a pattern that I am missing that may be a straightforward solution. An option would be to invalidate the cache when using a special value in set, but I don't think it is a good idea to assume a specific value for triggering the update.
getfunction would essentially contain that sort of logic. Here's an example: github.com/pyglet/pyglet/blob/… which rely quite hevily on this. Yoursetcould check if the value/key already exists and take action accordingly.ais a property of classA, thenb = A.acallsa.getter, whileA.a = bcallsa.setter. What syntax would you suggest that calls the 'updater'?deltriggers a special method. Perhaps there is anupd. Or perhaps descriptors are not the way to go and there is another approach I am not aware of. Or perhaps there is a way of knowing whethergetis being accessed with an extra.update?getterandupdater. If you want yourupdaterto have its own syntax, you would need to define a new operator.