[Python-ideas] Decorators for variables

Ian Kelly ian.g.kelly at gmail.com
Fri Apr 1 11:55:02 EDT 2016


On Fri, Apr 1, 2016 at 9:46 AM, Matthias welp <boekewurm at gmail.com> wrote:
>> > Currently the way to create variables with custom get/set/deleters is to
>> > use the @property decorator or use property(get, set, del, doc?), and
>> > this must be repeated per variable. If I were able to decorate multiple
>> > properties with decorators like @not_none or something similar, it
>> > would take away a lot of currently used confusing code.
>>
>> How does this prevent repetition?
>
> If you were to define a variable you currently could use the @property for
> each variable, which could take up to 3 declarations of the same name per
> use of the pattern. Using a decorator might take that down to only 1 extra
> line.

An example of the transformation that you intend would help here. If
you're intending this as a @property replacement then as far as I can
see you still need to write up to three functions that define the
property's behavior.


More information about the Python-ideas mailing list