[Python-Dev] The decorator(s) module

Alex Martelli aleaxit at gmail.com
Sat Feb 18 01:02:05 CET 2006


On 2/17/06, Georg Brandl <g.brandl at gmx.net> wrote:
> Ian Bicking wrote:
>
> >> Unfortunately, a @property decorator is impossible...
> >
> > It already works!  But only if you want a read-only property.  Which is
> > actually about 50%+ of the properties I create.  So the status quo is
> > not really that bad.
>
> I have abused it this way too and felt bad every time.
> Kind of like keeping your hat on in the church. :)

It's not ideal, because the resulting r-o property has no docstring:

>>> class ex(object):
...   @property
...   def amp(self):
...     ''' a nice docstring '''
...     return 23
...
>>> ex.amp.__doc__
>>> class xe(object):
...   def amp(self): return 23
...   amp=property(amp, doc='whatever!')
...
>>> xe.amp.__doc__
'whatever!'
>>>

Maybe we could fix that by having property(getfunc) use
getfunc.__doc__ as the __doc__ of the resulting property object
(easily overridable in more normal property usage by the doc=
argument, which, I feel, should almost invariably be there).


Alex


More information about the Python-Dev mailing list