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

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, firstargument)"). 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...).

Regards, Nick.

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



More information about the Python-Dev mailing list