PEP 726: Module __setattr__ and __delattr__

Hmm, I think the code example in the Motivation section is very concrete. Or are you about real world use cases? Another one given in the old thread, see the current workaround. The problem is that this solution slowdown also attribute access (more slow setting/deleting could be expected). Same workarounds with the __class__ attribute could be used for Victor examples, but in case of the sys module the price even less acceptable…

On another hand (and this was already mentioned above), this will simplify the mental model of customizing the module attribute access, i.e. a very basic thing for modules (c.f. something like the __call__ dunder). Currently we have streamline variants only for reading, but not for setting/deleting (as for class instances). Instead, now we are forced to use different patterns to customize attribute access in different scenarios…

Should I list mentioned above real world examples in the PEP?
Edit:
Here is some (incomplete) list of examples from the quick GH search:

On another hand, I’ve no examples for using other customized dunder methods for modules (except for the __call__).

1 Like