[Python-ideas] A (meta)class algebra

Martin Teichmann lkb.teichmann at gmail.com
Fri Feb 13 05:39:22 CET 2015


Hi Anthony, Hi list,

> Create the required inheriting metaclass on the fly:
>
> def multi_meta(*clss):
>     """A helper for inheriting from classes with different metaclasses.
>
>     Usage:
>         class C(multi_meta(A, B)):
>             "A class inheriting from classes A, B with different
> metaclasses."
>     """

That's actually exactly the code I am trying to avoid. This way, everyone
starts writing their own metaclass mixers, which all make strong
assumptions about the metaclasses being mixed.

Now there should be only one way of doing things in python, unfortunately
I'm not dutch so I don't see it. Maybe it would be a good idea to have
such a mixer in the standard library. It would then cache already generated
metaclasses. It would also ask the metaclasses on how they like to
be mixed.

Not before long, you will read recommendations like
"just always write class A(mixer(B, C)), because well, you never now
whether B or C have a metaclass". This is exactly why I would like
to put it up one more level, make it part of type.

Greetings

Martin


More information about the Python-ideas mailing list