[Python-ideas] An even simpler customization of class creation
Nick Coghlan
ncoghlan at gmail.com
Mon Mar 2 10:45:38 CET 2015
More information about the Python-ideas mailing list
Mon Mar 2 10:45:38 CET 2015
- Previous message (by thread): [Python-ideas] An even simpler customization of class creation
- Next message (by thread): [Python-ideas] An even simpler customization of class creation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 1 Mar 2015 19:28, "Martin Teichmann" <lkb.teichmann at 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150302/9593fbb3/attachment.html>
- Previous message (by thread): [Python-ideas] An even simpler customization of class creation
- Next message (by thread): [Python-ideas] An even simpler customization of class creation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list