[Python-Dev] Declaring setters with getters

Phillip J. Eby pje at telecommunity.com
Wed Oct 31 18:51:37 CET 2007


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.  :)



More information about the Python-Dev mailing list