<div dir="ltr">Hello,<div><br></div><div>This is my first post on python-dev and I hope that I am not breaking any rule.</div><div><br></div><div>I wanted to react on the discussion regarding PEP487.</div><div><br></div><div>This year, we have been working on a refactoring of the `traitlets` library, an implementation of the descriptor pattern that is used in Project Jupyter / IPython. The motivations for the refactoring was similar to those of this PEP: having a more generic metaclass allowing more flexibility in terms of types of descriptors, in order to avoid conflicts between meta classes.</div><div><br></div><div>We ended up with:</div><div>- A metaclass called MetaHasDescriptor</div><div>- A base class of meta MetaHasDescriptor named HasDescriptors</div><div><br></div><div>Usage:</div><div><br></div><div>class MyClass(HasDescriptors):<br></div><div>    attr = DesType()</div><div><br></div><div>DesType inherits from a base Descriptor type. The key is that their initialization is done in three stages</div><div><br></div><div> - the main </div><div>        <font face="monospace, monospace">DesType.__init__</font></div><div><br></div><div> - the part of the initialization of DesType that depends on the definition of MyClass</div><div>        <font face="monospace, monospace">DesType.class_init(self, cls, name)</font></div><div>   which is called from MetaHasDescriptors.__new__</div><div><br></div><div> - a method of DesType that depends on the definition of instances of MyClass</div><div>        <font face="monospace, monospace">DesType.instance_init(self, obj)</font></div><div>    which is called from HasDescriptors.__new__.</div><div><br></div><div>    instance_init, may make modifications on the HasDescriptors instance.<br></div><div><br></div><div>My understanding is that the proposed __set_name__ in PEP487 exactly corresponds to our class_init, although interestingly we often do much more in class_init than setting the name of the descriptor, such as setting a this_class attribute or calling class_init on contained descriptors. Therefore I do not think that the names __set_name__ or __set_owner__ are appropriate for this use case. </div><div><br></div><div>In a way, the long-form explicit names for our class_init and instance_init methods would be something like <font face="monospace, monospace">__init_fom_owner_class__</font>, and <font face="monospace, monospace">__touch_instance__.</font></div><br>Thanks,<br><br>Sylvain<div><br></div><div>PS: thanks to Neil Girdhar for the heads up on the traitlets repo.</div></div>