<div dir="ltr">In the traitlets library I mentioned earlier, we do have a need for this. The corresponding function is called `setup_class`.<div><br></div><div>What it does is setting some class attributes that are required for certain types of descriptors to be able to initialize themselves.<div><br><font face="monospace, monospace"><span class="gmail-pl-k" style="color:rgb(167,29,93)">class</span> <span class="gmail-pl-en" style="color:rgb(121,93,163)">MetaHasTraits</span>(<span class="gmail-pl-e" style="color:rgb(121,93,163)">MetaHasDescriptors</span>): </font></div><div><span class="gmail-pl-s" style="color:rgb(24,54,145)"><font face="monospace, monospace"><span class="gmail-pl-pds" style="box-sizing: border-box;"><br></span></font></span></div><div><span class="gmail-pl-s" style="color:rgb(24,54,145)"><font face="monospace, monospace"><span class="gmail-pl-pds" style="box-sizing: border-box;">    """</span>A metaclass for HasTraits.<span class="gmail-pl-pds" style="box-sizing: border-box;">"""</span></font></span></div><div><font face="monospace, monospace"><span class="gmail-pl-k" style="box-sizing: border-box;">    </span><span class="gmail-pl-k" style="color:rgb(167,29,93)">def</span><span class="gmail-pl-k" style="box-sizing: border-box;"> </span><span class="gmail-pl-en" style="color:rgb(121,93,163)">setup_class</span>(<span class="gmail-pl-smi" style="box-sizing: border-box;">cls</span>, <span class="gmail-pl-smi" style="box-sizing: border-box;">classdict</span>):</font></div><div><font face="monospace, monospace"><span class="gmail-pl-v" style="box-sizing: border-box;">        </span><span class="gmail-pl-v" style="color:rgb(237,106,67)">cls</span>._trait_default_generators <span class="gmail-pl-k" style="color:rgb(167,29,93)">=</span> {}</font></div><div><font face="monospace, monospace"><span class="gmail-pl-c1" style="box-sizing: border-box;">        </span><span class="gmail-pl-c1" style="color:rgb(0,134,179)">super</span>(MetaHasTraits, <span class="gmail-pl-v" style="color:rgb(237,106,67)">cls</span>).setup_class(classdict)</font></div><div><br></div></div><div><br></div><div>Sylvain</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 29, 2016 at 5:01 PM, Martin Teichmann <span dir="ltr"><<a href="mailto:lkb.teichmann@gmail.com" target="_blank">lkb.teichmann@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
there has been quite some discussion on why PEP 487's<br>
__init_subclass__  initializes subclasses, and not the class itself. I<br>
think the most important details have been already thoroughly<br>
discussed here.<br>
<br>
One thing I was missing in the discussion is practical examples. I<br>
have been using PEP 487-like metaclasses since several years now, and<br>
I have never come across an application where it would have even been<br>
nice to initialize the class itself. Also, while researching other<br>
people's code when I wrote PEP 487, I couldn't find any such code<br>
elsewhere, yet I found a lot of code where people took the wildest<br>
measure to prevent a metaclass in doing its job on the first class it<br>
is used for. One example is enum.EnumMeta, which contains code not to<br>
make enum.Enum an enum (I do not try to propose that the enum module<br>
should use PEP 487, it's way to complicated for that).<br>
<br>
So once we have a practical example, we could start discussing how to<br>
mitigate the problem.<br>
<br>
Btw, everyone is still invited to review the patch for PEP 487 at<br>
<a href="http://bugs.python.org/issue27366" rel="noreferrer" target="_blank">http://bugs.python.org/issue27366</a>. Many thanks to Nick who already<br>
reviewed, and also to Guido who left helpful comments!<br>
<br>
Greetings<br>
<span class="HOEnZb"><font color="#888888"><br>
Martin<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/sylvain.corlay%40gmail.com" rel="noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/sylvain.corlay%40gmail.com</a><br>
</div></div></blockquote></div><br></div>