Re: [Python-Dev] Declaring setters with getters
At 10:08 AM 10/31/2007 -0700, Guido van Rossum wrote:
I've come up with a relatively unobtrusive pattern for defining setters. Given the following definition:
def propset(prop): assert isinstance(prop, property) def helper(func): return property(prop.__get__, func, func, prop.__doc__) return helper
Shouldn't that be property(prop.fget, func, prop.fdel, prop.__doc__), and have a matching propdel decorator? Apart from those extremely small nits, a big +1, and I expect to swipe this idea more or less immediately. :)
I'd also like to change property so that the doc string defaults to the doc string of the getter.
+1 also; I thought it did this already, but am now disappointed to find it doesn't. :)
On 10/31/07, Phillip J. Eby
At 10:08 AM 10/31/2007 -0700, Guido van Rossum wrote:
I've come up with a relatively unobtrusive pattern for defining setters. Given the following definition:
def propset(prop): assert isinstance(prop, property) def helper(func): return property(prop.__get__, func, func, prop.__doc__) return helper
Shouldn't that be property(prop.fget, func, prop.fdel, prop.__doc__),
Of course. (Though my code works too. :-)
and have a matching propdel decorator?
Yes, though I think that if prop.fdel is None, we could use func in both slots.
Apart from those extremely small nits, a big +1, and I expect to swipe this idea more or less immediately. :)
Be my guest. I should patent this; it's apparently non-obvious. :-) (I can't recall why I didn't think of this sooner, and why nobody else did.)
I'd also like to change property so that the doc string defaults to the doc string of the getter.
+1 also; I thought it did this already, but am now disappointed to find it doesn't. :)
Patch for 2.6 anyone? -- --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (2)
-
Guido van Rossum
-
Phillip J. Eby