PEP 726: Module __setattr__ and __delattr__

I read the PEP and I don’t find the motivation compelling. The PEP lists a few categories of use cases (e.g., “To prevent setting an attribute at all (i.e. make it read-only)”), but gives no concrete examples. I haven’t personally felt a need for it or heard of a lot of cases where it is useful. Victor gives a good example above with sys, but I’m not sure a single module is enough to justify a language change.

Normally dunders are looked up on the class, not the instance. This PEP would add two exceptions to that rule. We have two similar exceptions already for modules (__getattr__ and __dir__), but any additional exceptions would further muddy the general rule. We shouldn’t do it without a strong motivation.

2 Likes