ARTICLE AD BOX
In the Python program my colleagues and I are writing, we have one very important class that needs to be protected against having its properties changed erroneously. This class controls a lot of things, and is capable of writing itself to a JSON file. If it writes itself to file in a bad state, it could cause huge problems and require rollbacks, restore from backups, etc.
What I would love to do is protect access to nearly all of its parameters, one way or another. The problem is, as far as I understand it, Python classes don't really have the concept of private properties, so we can't prevent or gatekeep all changes to properties.
What we've done instead is basically introduced a poison pill. Certain functions that are called on the class will flip an "unwriteable" flag to true, and crash the program if the class is written to the file. This is a good start, but I'd like to extend the practice. What I want to do is execute a function anytime a property changes, and determine if we should poison the whole class.
Is there any way to have a function execute any time a class's properties change? Or is there another way of doing what we're trying to do?
