[Python-Dev] metaclass insanity
Guido van Rossum
guido@python.org
Wed, 30 Oct 2002 11:44:36 -0500
> I guess one way of doing this would be to reimplement mro resolution
> and so on in Python, which would be annoying and inefficient. Hmm.
Alas, yes. You'd have to be able to write a class's tp_mro slot
(corresponding to the __mro__ attribute), but there's no way to do
that in Python, because it is too easy to cause mistakes. E.g. all
C code that currently uses tp_mro assumes that it is a tuple whose
items are either types or classic classes.
The best thing to do would perhaps to make __mro__ assignable, but
with a check that ensures the above constraint. I think I'd take a
patch for that.
I'd also take a patch for assignable __bases__. Note that there are
constraints between __bases__ and __base__.
I'd also take a patch for assignable __name__.
--Guido van Rossum (home page: http://www.python.org/~guido/)