Use the class Protected as a parent.
To install protectedclasses, you can use pip. Open your terminal and run:
pip install protectedclassesclass Protected:
def __setattr__(self, name, value):
cls = type(self)
if name.startswith("_"):
super().__setattr__(name, value)
return
if isinstance(getattr(cls, name, None), property):
super().__setattr__(name, value)
return
e = "%r object has no property %r"
e %= (cls.__name__, name)
raise AttributeError(e)This project is licensed under the MIT License.
- Author: Johannes
- Email: johannes-programming@mailfence.com
Thank you for using protectedclasses!