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

Martin Teichmann lkb.teichmann at gmail.com
Mon Feb 16 17:19:54 CET 2015


Hi list,

> Again, Python already has a metaclass that everyone is supposed to
> use, namely `type`.

well, there is a problem out here: people are indeed using other
metaclasses. Even the standard library, like ABC or enums.

And there is a problem here in python: once you do multiple inheritance,
and two classes have different metaclasses, there is no way of
programmatically determining an appropriate metaclass.

Sure, one can be of Thomas' opinion that doing so is a bad idea
anyways, but there are other people who think that writing and
combining metaclasses actually is thing one can do.

Especially for simple cases I do think that metaclasses are a good
idea and there should be a way to tell python how to combine two
metaclasses.

I am trying to solve this problem. What I posted was just one simple
idea how to solve it. Another one is the idea I posted earlier, the
idea was to add metaclasses using __add__. People didn't like the
__add__, so I implemented that with a new method called merge,
it's here: https://github.com/tecki/cpython/commits/metaclass-merge

Instead of yelling at me that my solutions are too complicated,
it would be very helpful and constructive to answer the following
questions:

- is it desirable to have a programmatic way to combine metaclasses?
- if yes, how should that be done?

My idea is that yes, it is desirable to have a programmatic way of
combining metaclasses, and I have now proposed two ways how to
do that.

Greetings

Martin


More information about the Python-ideas mailing list