smarie/python-autoclass

Being able to customize all or a subset of generated getters and setters at once

smarie opened this issue · 1 comments

New annotations @getters_wrapper(include, exclude) and @setters_wrapper(include, exclude), that would use @contextmanager or directly extend GeneratorContextManager in order to help users add functionality to all or some of the generated getters/setters with a function containing yield. For example in order to add a log message whenever properties are changed, the user would add a single log_property_change method to the class, decorated with @setters_wrapper.

This issue was mainly to reduce the amount of code required when writing attribute validation in overriden setters. It is less of a priority now that we have the @validate annotation.