[Python-ideas] wild idea : target decorators
Guido van Rossum
guido at python.org
Fri Sep 25 05:38:24 CEST 2009
On Thu, Sep 24, 2009 at 7:20 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
>> On Thu, Sep 24, 2009 at 5:38 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
>>> foo = 'The fancy foo property'
>> How did one occurrence of 'foo' suddenly turn into foo (without
>> quotes)? That's not how decorators behave elsewhere.
> Decorators on assignments would have to be defined slightly
> differently, since as you point out, they wouldn't gain
> you anything otherwise.
> If you would prefer to use some syntax other than @ for
> this, that would be fine with me. All I'm asking for is
> *some* way to write things like this without having to
> repeat the name of the thing being defined. There doesn't
> seem to be any way to do that at the moment without
> abusing some other construct, such as using a 'def'
> when you aren't really defining a function.
So, you don't care abut the repetition of x in "x = f(x)" but you'd
like to have a way to implicitly pass an argument giving the string
name of the target variable, like "x = f('x')" ? (Or "x = f('x', x)";
it's the same thing really.) That certainly has nothing to do with
decorators. I'm not sure that it's common enough to warrant special
syntax; certainly "x = f(x)" must be a lot more common without also
needing to pass in the string 'x'.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-ideas