There was a beautiful way to organize class property in frame of one function, by using the apply decorator.
class Example(object):
@apply
def myattr():
doc = """This is the doc string."""
def fget(self):
return self._half * 2
def fset(self, value):
self._half = value / 2
def fdel(self):
del self._half
return property(**locals())
But now apply has been deprecated.
Is there any possibility to achieve such simplicity and readability for property, with new, came instead “extended call syntax”?
My approach is same as Anurag’s, but, I don’t now witch one is better, please look:
def prop(f):
return property(**f())
class A(object):
@prop
def myattr():
def fget(self):
return self._myattr
def fset(self, value):
self._myattr = value
return locals()
The new Python 2.6 way is: