[Python-ideas] A way out of Meta-hell (was: A (meta)class algebra)

Nick Coghlan ncoghlan at gmail.com
Thu Feb 19 22:35:11 CET 2015


On 19 February 2015 at 22:22, Martin Teichmann
<martin.teichmann at gmail.com> wrote:
>> Yes, populating __class__ happens inside the interpreter only after the
>> class is fully constructed, so even though the *class* is fully initialised
>> at the end of __init__, a reference hasn't been inserted into the cell yet.
>> (The __class__ cell doesn't actually live on the class object - it's created
>> implicitly by the interpreter and then referenced from the individual
>> methods as a closure variable for each method that looks up "__class__" or
>> "super")
>>
>> Python 2 doesn't provide the implicitly populated __class___ cell at all
>> though, so you have to refer to the class object by its name - zero argument
>> super is a Python 3 only feature.
>
> In short: PEP 422 in the current form is not back-portable.
> With my modifications it is portable all the way down to python 2.7.
>
> PEP 422 being back-portable => people will immediately start using it.
> PEP 422 not back-portable => it won't be used for several years to come.

You haven't really explained why you think it's not backportable.
You've suggested a backport may require some workarounds in order to
handle cooperative multiple inheritance, but that's not even close to
being the same thing as not being able to backported at all.

That said, if you'd like to write a competing proposal for the
community's consideration, please go ahead (details on the process are
in PEP 1)

I'm certainly open to alternative ideas in this space, and PEP 422 is
deferred specifically because I don't currently have time to explore
those ideas further myself.

Regards,
Nick.

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


More information about the Python-ideas mailing list