[Python-ideas] A (meta)class algebra
Martin Teichmann
lkb.teichmann at gmail.com
Fri Feb 13 12:13:49 CET 2015
Hi Petr, Hi list,
> This is the one thing keeping metaclasses from being truly general –
> using them limits inheritance.
I agree. That was why I am proposing a solution to this problem.
> The problem is that metaclasses are too powerful.
> They can change the C-level type; you can't automatically combine two
> metaclasses that do this.
This is exactly the problem my proposal solves. In my proposal,
metaclasses will NOT be combined automatically, but the authors
of the metaclasses have to explicitly write a method that does the
job. If that's not possible, the method is free to fail, like raising
an error (if one follows my idea with __add__, then it should
return NotImplemented)
> (And btw, __add__ is a terrible name
> for the method. If it's meant to be called implicitly by Python the
> "+" sugar is unnecessary. Something like __metaclass_combine__ would
> be a better name.)
I'm fine with any name. I just thought it to be useful that the entire
machinery with __add__ and __radd__ are already there.
> Anyway, perhaps "simple" metaclasses can be combined automatically? Or
> there could be an instantiation hook to enable these classes without
> limiting subclassing?
well, my proposal is such a hook.
Greetings
Martin
More information about the Python-ideas
mailing list