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
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:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.pyx", line 16, in test.main (test.c:489)
b = B()
File "test.pyx", line 4, in test.A.__init__ (test.c:380)
self.me = "A"
AttributeError: can't set attribute
I haven't tested it, but I'd guess that, had I provided a setter method
for the property, too, A.__init__ would not have used it when called for
a B object.
Cheers
Simon
+---
| Dr. Simon Anders, Dipl.-Phys.
| European Molecular Biology Laboratory (EMBL), Heidelberg
| office phone +49-6221-387-8632
| preferred (permanent) e-mail: [email protected]
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev