[Python-ideas] A (meta)class algebra

Antony Lee antony.lee at berkeley.edu
Fri Feb 13 18:27:56 CET 2015


While PEP422 is somewhat useful for heavy users of metaclasses (actually
not necessarily so heavy; as mentioned in the thread you'll hit the problem
as soon as you want to make e.g. a QObject also instance of another
metaclass), I don't like it too much because it feels really ad hoc (adding
yet another layer to the already complex class initialization machinery),
whereas dynamically creating the sub-metaclass (inheriting from all the
required classes) seems to be the "right" solution.  In a sense, using an
explicit and ad hoc mixer ("__add__") would be like saying that every class
should know when it is part of a multiple inheritance chain, whereas the
implicit ("multi_meta") mixer just relies on Python's MRO to do the right
thing.  Of course, best would be that the "multi_meta" step be directly
implemented at the language level, and I agree that having to add it
manually isn't too beautiful.

__init_class__ could then simply be implemented as part of a normal
metaclass, from which you could inherit without worrying about other
metaclasses.

Antony

2015-02-13 5:27 GMT-08:00 Martin Teichmann <lkb.teichmann at gmail.com>:

> Hi,
>
> me too, I missed that PEP, and yes, it would certainly work
> for all my needs.
>
> In short words, the PEP reads: forget all that metaclass stuff,
> here comes the real solution. Maybe we can even abandon
> metaclasses altogether in Python 4, I think noone would shed
> a tear over them.
>
> But if the metaclass fans should win the battle, I would like
> my proposal included sometimes.
>
> Greetings
>
> Martin
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150213/bed6230c/attachment.html>


More information about the Python-ideas mailing list