Re: [Pyobjc-dev] Dot syntax style setters.
Brought to you by:
ronaldoussoren
|
From: Ronald O. <ron...@ma...> - 2009-03-29 18:20:03
|
On 29 Mar, 2009, at 13:03, Bill Bumgarner wrote: > On Mar 29, 2009, at 7:41 AM, Ronald Oussoren wrote: >> The easy one is properties: I'd love to use "someObject.size = 5" >> instead of "someObject.setSize_(5)". This is fairly easy to >> implement, although defining custom read-accessors makes live >> slightly more interesting (you cannot have a property named "foo" >> and a method named "foo" in the same class in PyObjC). The >> largest blob of work for this is generating the right metadata for >> PyObjC. > > The ObjC rule for the above is that someObject.size is exactly > equivalent to [someObject size] (get) or [someObject setSize: 5] > (set). > > If PyObjC can implement it with the same level of exactness, it > makes sense to do and would be a boon. The annoying bit is that method names and attribute names are in the same namespace on Python, which makes it impossible to make both someObject.size valid as a property and someObject.size() valid as a getter. It would be possible to use metaclass trickery to allow defining a 'size' getter method and still have the 'size' property, at the cost of breaking all existing code that uses the getter methods. That's why I'd be reluctant to add this without also implementing some kind of fix for the overly long method names. Any change in this field would IMHO also require a refactoring tool to automate the transition. That should at least be doable using the lib2to3 machinery that's in python 2.6; that name is misleading the code actually implements a Python refactoring engine that happens to be configured with Python 2 -> Python 3 refactorings. Ronald > > b.bum |