On Fri, Dec 3, 2010 at 11:07 AM, Dag Sverre Seljebotn
<[email protected]> wrote:
> On 12/03/2010 08:05 PM, Stefan Behnel wrote:
>> Robert Bradshaw, 03.12.2010 19:57:
>>
>>> On Fri, Dec 3, 2010 at 10:53 AM, 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)
>>>>>>
>>>>>>
>>>> Given that these two fields carry the
>>>> same name as the Python visible attributes, this introduces behaviour that
>>>> diverges from CPython's own behaviour. Making these fields mutable means
>>>> that you will get an exception when you modify the field in CPython but a
>>>> straight value update after you compiled your code.
>>>>
>>> Of course we have exactly the same asymmetry for the read-only
>>> attributes of typed cdef classes.
>>>
>> Sure. But I think it's a difference if you allow users to change the values
>> of their own types, or if you allow them to accidentally change the value
>> of an internal type of the CPython runtime.
>>
>
> +1. If we end up with stuff like this it's going to be a major pain for
> users:
>
>  >>> x = 1 + 2j
>  >>> f(x)
>  >>> print x
> (300 + 4j)

I can see a usecase for it--for example if you're evaluating a
user-defined function at many different values and don't want to
re-allocate the object, but in that case I'm willing to force the user
to jump through some extra trickery.

- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to