On 3 December 2010 15:10, Stefan Behnel <[email protected]> wrote: > Hi, > > I just implemented C access to the fields of CPython's builtin types like > this: > > cdef complex c = 1+2j > c.real, c.imag = 10, 20 > print (c.real, c.imag) > > and then noticed that "real" and "imag" are actually read-only in Python. > So I wonder if we should disallow the above (i.e. raise a compiler error > during type analysis) and instead only allow this: > > cdef complex c = 1+2j > cval = &c.cval > cval.real, cval.imag = 10, 20 > print (c.real, c.imag) > > (which also works now, BTW). > > Opinions? >
No! No! No! In Python, you cannot assign to real or imag simply because the complex is immutable (like Python ints and floats). For C types, immutability does not apply! -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
