Robert Bradshaw, 02.11.2010 07:17:
> On Sun, Oct 31, 2010 at 8:44 PM, Brett Calcott wrote:
>> But it really makes things easy. I don't have to declare
>> all the properties independently. And when I need the cpp version, I just
>> pass around pointer.
>> Something like this would be nice:
>> cdef class PythonVector2d:
>>    cdef Vector obj
>>    properties:
>>       public obj.x as x
>>       public obj.y as y
>> Does this look crazy?
>
> A better way to specify "simple" properties would be nice. Another
> option would be
>
>      property obj.x as x
>
> or
>
>      property x:
>          obj.x
>
> which would create a getter and setter automatically (if the body is
> an expression).

For this case, I'd prefer a version entirely without body, maybe even

     property x = obj.x

although the "as" version would also work. However, it's not so clear from 
the above that both setter and getter get generated, and how you would get 
only the getter for read-only access, for example. And why not have a 
"delattr" as well? May make sense in some cases.

Personally, I think that the current way of coding this isn't all that 
cumbersome but a lot more explicit. And it makes you think a bit more about 
the implications of mapping a C++ class field directly to a Python property 
without value checking etc.

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

Reply via email to