mark florisson, 04.11.2010 14:01:
> On 4 November 2010 13:15, Stefan Behnel wrote:
>> http://www.python.org/dev/peps/pep-3115/
>>
>> Apparently, __prepare__ is meant to be executed *before* even evaluating
>> the class body
>> So it's basically what gives you the dict that you assign the class members
>> to (as you did in your original patch).
>>
>> I do not see why we should currently implement this, given that
>> __build_class__ doesn't seem to follow that protocol either. It would just
>> slow down the evaluation of the class body as we could no longer rely on
>> the class dict being a dict.
>>
>> I think we can just ignore that part of the protocol for now - I doubt that
>> many people will use it (or even know about it). Maybe worth a feature
>> request on the bug tracker, but not more.
>
> As the PEP mentions, __prepare__ is especially useful for establishing
> in what order members are defined. To quote:
>[...]
> If it's a hassle to implement then users could always just write this
> stuff in pure python though (as they have to do currently).

Well, "pure Python" in the sense that the whole class needs to be put into 
a Python module. Changing the class dict needs runtime support as it must 
happen when the code evaluation starts running into the class body. It 
cannot be done from within the class building function, which is executed 
at the end of the class body.

This implies that it only works with metaclasses that really are defined as 
part of the class declaration, i.e. in Py3 syntax. A __metaclass__ field 
will be detected too late in the class building cycle to make this work.

I'm not really opposed to implementing this. I'm just saying that it would 
complicate things for an extremely rare use case. If someone wants to do 
it, why not.

BTW, I'll ask on python-dev about the way __build_class__ works here.

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to