On 1 Mar 2015 19:28, "Martin Teichmann" <lkb.teichmann@gmail.com> wrote:
Aye, I like this design, it just wasn't until I saw it written out fully that it finally clicked why restricting it to subclasses let both zero-argument super() and explicit namespace access to the defining class both work. Getting the latter to also work is a definite strength of your approach over mine.
That said, I would love if it was just possible to use super() in classmethods called from the __init__ of a metaclass. Until now, the __class__ of a method is only initialized after the metaclasses __init__ has run.
Fortunately, this is easily changeable: it is possible to move the initialization of __class__ into type.__new__. As the class is (typically) created there, that is about as early as possible.
Unfortunately, it's too early - we can't control whether or not subclasses actually return the result of type.__new__ from their own __new__ implementation, so that object could have been replaced by something else by the time __init__ gets called. However, it may be feasible to move it into type.__init__. That way class methods would start working properly as soon as the metaclass __init__ implementation had called up into type.__init__. Regards, Nick.