Enhanced property decorator

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Aug 26 04:15:30 CEST 2008

Daniel <millerdev at gmail.com> writes:

> I've often been frustrated by the inability of the built-in property
> descriptor to handle anything other than a read-only property when
> used as a decorator.

The fact that the 'property' function works as a decorator (in, as you
point out, some cases only) is a happy accident. The 'property'
function isn't *designed* to be used as a decorator, it just happens
to work that way.

> Solution 1: new built-in function/descriptor

> Solution 2: Enhance the built-in property descriptor

> Solution 3: […] require new syntax for the yield keyword, which
> would yield an unnamed function object (similar to a lambda object).

All of these require changes in Python or its standard library.

Here are some solutions that work now, with Python as it is, for using
decorators to implement full-featured properties

 \       “Try to learn something about everything and everything about |
  `\                                          something.” —T.H. Huxley |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list