[Python-ideas] A way out of Meta-hell (was: A (meta)class algebra)

Nick Coghlan ncoghlan at gmail.com
Tue Feb 17 23:33:27 CET 2015


On 17 Feb 2015 23:29, "Martin Teichmann" <lkb.teichmann at gmail.com> wrote:
>
> Hi again,
>
> OK, so if my ideas don't get through, would it at least be possible
> to make PEP 422 have an __init_subclass__ only initializing the
> subclasses of the class? That would have the great advantage of
> being back-portable as a metaclass all the way down to python 2.7.
> I guess this would help PEP 422 being actually used a lot.

Zope already implements __classinit__ via a metaclass, so I'm not clear on
how this addition would help with a backport of the __init_class__ spelling
to Python 2.

PEP 422 largely proposes standardisation of an existing custom metaclass
capability (using a different method name to avoid conflicting) for
improved ease of use, discoverability and compatibility, rather than making
any fundamental changes to the type system design.

I agree a clean idiom for detecting whether you're in the base class or not
might be useful, but even without specific support in the PEP you'll at
least be able to do that either by inspecting the MRO, or else by assuming
that the class name not being bound yet means you're still in the process
of creating it.

Regards,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150218/b62f6336/attachment-0001.html>


More information about the Python-ideas mailing list