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:
- https://github.com/pytorch/pytorch/blob/main/torch/_dynamo/config_utils.py#52 - only
__get/set/delattr__
magic methods are really required - https://github.com/perone/pytorch/blob/master/torch/_dynamo/config.py#L175 - older variant of above?
- https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/shared_items.py#L98
- https://github.com/py-pdf/fpdf2/blob/master/fpdf/deprecation.py#L16 - here it’s to issue a DeprecationWarning for setting some module attributes
On another hand, I’ve no examples for using other customized dunder methods for modules (except for the __call__
).