-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attribute changed notification hooks #622
Comments
What you're asking for is attrs to start writing a You should be able to implement it yourself for now: put the hooks into the attribute's meta field and write a |
If I remember correctly it's a pile (of bad stuff) and maybe I shouldn't share it here... but I wrote up an implementation of this idea for use in my PyQt applications. It definitely needs to be rewritten. It went the route of generating code: https://github.com/altendky/stlib/blob/fc519e561adddb930c1dc7cdc6a74bd5290d3c95/epyqlib/utils/qt.py#L914 Anyways, hopefully this doesn't waste someone else's time. Figured I'd share something rather than just clicking the subscribe button. |
@danieljfarrell hi Daniel, are you planning to work on it? Otherwise I can pick this up. This feature will be handy in our org. |
@gshaikov I’m afraid I had to move on to other things. I’ve not made any progress with this. |
@hynek I saw your comment from 2017 about |
I literally wrote it in the next sentence. :). I didn't want to touch another dunder method but that reason has fallen away since we do touch |
I guess I could imagine an API similar to this: x = attr.ib(set_hook=validate_if_has_validator) with the usual syntactic sugar for combination using lists. |
Please have a look at #660. |
I believe this is fixed. |
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.The text was updated successfully, but these errors were encountered: