[Cython] PEP 3135 -- New Super
stefan_ml at behnel.de
Tue Jul 12 12:42:44 CEST 2011
mark florisson, 12.07.2011 12:11:
> On 12 July 2011 11:46, Vitja Makarov wrote:
>> 2011/7/12 Stefan Behnel
>>> Vitja Makarov, 12.07.2011 09:46:
>>>> About cdef classes: probably it's better to
>>>> transform super().method(...) into direct form, e.g. BaseClass.method(self,
>>> Except when it doesn't work. ;)
>>> / \
>>> B C
>>> \ /
>>> The MRO here is D-B-A-C. If C unconditionally calls A.method(), A's implementation will be called twice, as it was already called by B.
>> According to your link mro in the example is DBCA ;)
Totally proves my point. ;)
>> Is that a problem for cdef classes? Cdef class have only one base, isn't it?
> That is irrelevant, if B calls A's method then C's method will be
> skipped. If it would use super() it would call C's method, and C's
> method would call A's method.
Exactly. So, calling directly into the base classes method implementation
(i.e. issuing a direct C function call) makes a suitable optimisation for
"final" classes, but not for the general case.
More information about the cython-devel