On Fri, Oct 29, 2010 at 1:30 PM, Lisandro Dalcin <[email protected]> wrote:
> On 28 October 2010 19:52, Simon Anders <[email protected]> wrote:
>> Hi
>>
>> I might have found a subtle bug regarding Cython's handling of
>> polymorphic classes: When a class contains a field, and a daughter class
>> overlays the field with a property, a method of the base class will fail
>> to notice this when called for an object of the daughter class.
>>
>> If this sounded convoluted, an example might be clearer:
>>
>> --8<--
>> cdef class A( object ):
>>
>>    cdef str me
>>
>>    def __init__( self ):
>>       self.me = "A"
>>
>>    def whoami( self ):
>>       return self.me
>>
>> cdef class B( A ):
>>
>>   �...@property
>>    def me( self ):
>>       return "B"
>>
>> def main():
>>    b = B()
>>    print b.me
>>    print b.whoami()
>> --8<--
>>
>> The output of main() is:
>> B
>> A
>>
>
> Expected.
>
>>
>> However, the equivalent Python code, i.e., the same file, without the
>> 'cdef's before the 'class' statement and without the line 'cdef str me',
>> produces an error, namely:
>>
>
> Actually, you Python code is not equivalent. cdef classes are
> extension types, and they behave different. if you remove "cdef", you
> will get regular Python classes, and the code will work as you are
> expecting.

Of course, unless there's a compelling performance (or major backwards
compatibility) reason why things can't be otherwise, I'd prefer cdef
classes to work as much like def classes as possible.
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to