[Python-Dev] Submitting PEP 422 (Simple class initialization hook) for pronouncement

Nick Coghlan ncoghlan at gmail.com
Tue Feb 12 08:16:56 CET 2013

On Tue, Feb 12, 2013 at 8:35 AM, Guido van Rossum <guido at python.org> wrote:
> On Mon, Feb 11, 2013 at 2:29 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> 4.__class__ is already bound as soon as we have a class object to bind it
>> to, so we can't move it any earlier. However, it's already early enough to
>> let references to it from the new method (including the implied one in
>> zero-arg super) work properly. The black magic that is zero-arg super also
>> deals with PJE's concern about propagating the actual class up the MRO (as
>> it is equivalent to "super(__class__, first_argument)").
> So where is it not bound when a metaclass runs? I guess in the metaclass's
> __new__()? Because in the metaclass's __init__() it should exist IIUC.

I stand corrected, we don't *quite* bind it as soon as the class
object exists - we bind it as soon as the call to the metaclass
returns. So even though the class object exists when __init__ runs, it
isn't bound to __class__ yet. Given that the class construction
machinery treats the metaclass constructor as an opaque callable,
trying to get the cell binding to happen between the call to __new__
and the one to __init__ would be rather challenging (Translation: I'm
not sure where you would even start...).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list