-
-
Notifications
You must be signed in to change notification settings - Fork 424
Closed
Labels
Description
I'm interested in extending attrs to provide change notifications. Or at least making my classes generated with attrs emit notifications when an attribute changes.
How would you go about doing this?
I'm wondering if attrs could generate an 'x'_did_change method/notification hook when synthesizing the attributes. This is similar to traitlets trait change notifications/observations although that's more dynamic as observers can be added and removed at runtime.
import attr
import typing
@attr.s(auto_attribs=True)
class SomeClass:
a_number: int = 42
list_of_numbers: typing.List[int] = attr.Factory(list)
def _a_number_did_change(self, info):
old = info['old']
new = info['new']
def _list_of_numbers_did_change(self, info):
added = info['added']
removed = info['removed']Reactions are currently unavailable