On Tue, Nov 2, 2010 at 10:13 PM, Stefan Behnel <[email protected]> wrote: > Robert Bradshaw, 03.11.2010 02:16: >> On 2 November 2010 20:02, Stefan Behnel wrote: >>> Robert Bradshaw, 02.11.2010 07:17: >>>> On Sun, Oct 31, 2010 at 8:44 PM, Brett Calcott wrote: >>>>> cdef class PythonVector2d: >>>>> cdef Vector obj >>>>> properties: >>>>> public obj.x as x >>>>> public obj.y as y >> <--- snip --> >>> 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. >> >> setters, getters, (and delattrs?) would be defined iff they make sense >> on the expression in question. One could imagine >> >> property readonly obj.x as x >> >> or something like that. > > I'm generally ok with such an addition. > > What about something like > > cdef class PythonVector2d: > cdef Vector obj > cdef public x from obj.x
I think of "cdef" as something accessible from c. This could be OK it did c-level attribute renaming as well. (Hmm... maybe I'd be OK with that, but it feels a bit odd to create this alias on the C level.) > ? I'm wondering if it isn't better to keep the existing attribute syntax > than to introduce a new property syntax. Although, a counter argument could > be that it isn't really an attribute... Yep. It's nice to look at the class and be able to visualize its struct. > Next try: > > cdef class PythonVector2d: > cdef Vector obj: > property x > property readonly y as my_y > > Makes it clearer where the properties actually come from. This doesn't allow arbitrary expressions. On that note, should we require an explicit self.obj.x, or is self implicit? (The latter makes it impossible to refer to non-attributes, and is bad according to the zen of Python...), so I'd lean against this one. > Anyway, I won't object to your plain "property ... as ..." proposal above. Or "property ... from ..." if the name should be first (I don't have a strong preference, but the as is a more idiomatic keyword to use here). - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
