On Fri, Dec 3, 2010 at 10:56 AM, Dag Sverre Seljebotn <da...@student.matnat.uio.no> wrote: > On 12/03/2010 07:53 PM, Stefan Behnel wrote: >> Lisandro Dalcin, 03.12.2010 19:39: >> >>> On 3 December 2010 15:10, Stefan Behnel wrote: >>> >>>> 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! >>> >> I understand that. However, I hope that you are talking about the builtin >> Python complex type just like I am. Given that these two fields carry the >> > > No. If you do "cdef complex c", what you have is a C complex type. > > How would you treat "cdef float complex c"? Python has no object for > single precision complex.
cdef complex c is (as of a couple of changesets ago?) the Python complex object. I'm not sure I like it--feels a bit like bool or int. - Robert _______________________________________________ Cython-dev mailing list Cython-dev@codespeak.net http://codespeak.net/mailman/listinfo/cython-dev