In the traitlets library I mentioned earlier, we do have a need for this. The corresponding function is called `setup_class`. What it does is setting some class attributes that are required for certain types of descriptors to be able to initialize themselves. class MetaHasTraits(MetaHasDescriptors): """A metaclass for HasTraits.""" def setup_class(cls, classdict): cls._trait_default_generators = {} super(MetaHasTraits, cls).setup_class(classdict) Sylvain On Fri, Jul 29, 2016 at 5:01 PM, Martin Teichmann <lkb.teichmann at gmail.com> wrote: > Hello, > > there has been quite some discussion on why PEP 487's > __init_subclass__ initializes subclasses, and not the class itself. I > think the most important details have been already thoroughly > discussed here. > > One thing I was missing in the discussion is practical examples. I > have been using PEP 487-like metaclasses since several years now, and > I have never come across an application where it would have even been > nice to initialize the class itself. Also, while researching other > people's code when I wrote PEP 487, I couldn't find any such code > elsewhere, yet I found a lot of code where people took the wildest > measure to prevent a metaclass in doing its job on the first class it > is used for. One example is enum.EnumMeta, which contains code not to > make enum.Enum an enum (I do not try to propose that the enum module > should use PEP 487, it's way to complicated for that). > > So once we have a practical example, we could start discussing how to > mitigate the problem. > > Btw, everyone is still invited to review the patch for PEP 487 at > http://bugs.python.org/issue27366. Many thanks to Nick who already > reviewed, and also to Guido who left helpful comments! > > Greetings > > Martin > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/sylvain.corlay%40gmail.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160729/c8b6e871/attachment.html>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4