[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)

Joao S. O. Bueno jsbueno at python.org.br
Fri Mar 4 00:01:59 CET 2011

On Thu, Mar 3, 2011 at 7:40 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Ethan Furman wrote:
>> Greg Ewing wrote:
>>> I think we should have assignment decorators.
>>> @decorator
>>> lhs = rhs
>> That seems very verbose -- part of the issue for me is all the extra
>> typing involved in specifying the name twice, and I don't think this is
>> going to save many, if any, keystrokes.
> I don't follow. It costs an @ and a newline, but it saves
> one instance of the name, plus two quotes, a comma and
> perhaps a space.
> Anyway, the main issue for me in violating DRY isn't the
> number of keystrokes. The main issues are:

I liked the idea of an assignment decorator for these cases.

Even the Constants, that made an appearance on python-dev a few months
ago(and I suppose that at some point they should come into python 3.3
) could benefit from that.

Let's think a little more on this syntax for assigment decorators.

There _is_ currently a way of doing a similar thing, without new
syntax -- but that would involve
changing the f_locals of the calling frame on the constructor of the
named object. (which is just DoublePlusUngood)

What use cases could we have for it?
If there is a syntax change, can it do more things than an implicit
first parameter
to a function call? Or would that suffice?


> * It's harder to read -- the repeated name is just noise
>  that doesn't convey any useful information to the reader.
> * It's harder to maintain -- if you change the name, you
>  have to remember to change it in both places.
> --
> Greg
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

More information about the Python-ideas mailing list