Brett Calcott, 04.11.2010 04:51:
> On 4 November 2010 14:34, Robert Bradshaw wrote:
>> On Wed, Nov 3, 2010 at 8:24 PM, Brett Calcott wrote:
>>> On 3 November 2010 19:24, Dag Sverre Seljebotn  wrote:
>>>> cdef class A:
>>>>      cdef Vector obj
>>>>      x = delegate_property(obj, 'x')
>>>>
>>>> or similar, without throwing in new syntax. But it may be too late and I
>>>> don't care too much. Remember that "x = property(...)" is already in 
>>>> Python.
>>>
>>> This looks like an interesting option, especially if it was possible
>>> to write your own reusable "xxxx_property" functions that did "the
>>> right thing" for the particular object/library being wrapped. This
>>> would remove a lot boilerplate code that is normally cut and pasted
>>> for setter/getter functions. So, in a case where the C++ members are
>>> private, but access is provided via camelcase set/get functions,
>>> instead of
>>>
>>> property value:
>>>   def __get__(self):
>>>     return self.obj.getValue()
>>>   def __set__(self, int x):
>>>     self.obj.setValue(x)
>>>
>>> We could write:
>>> x = camelcase_delegate_property(self.obj, 'value')
>>
>> The one thing that I don't like about this is putting the attribute in
>> a String.
>
> Is this possible?
>     x = member_property(self.obj.x)
>     y = getset_property(self.obj.getY, self.obj.setY)

The latter could be mapped to Python's own property() with a bit of minor 
magic, I think. However, we don't currently implement property() ourselves, 
so a builtin property transmogrification transform would be the first step.

http://trac.cython.org/cython_trac/ticket/264

Apart from that, I agree with Robert that the parser should see the name of 
the field, and that for anything more fancy than a simple expression, the 
spelled-out syntax is the way to go.

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

Reply via email to