[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)
jackdied at gmail.com
Fri Mar 4 05:53:07 CET 2011
On Thu, Mar 3, 2011 at 3:45 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
>> That is, something that
>> made it feasible to reference the name on the left hand side of a
>> simple assignment without needing to repeat it as a string with the
>> same contents.
> I think we should have assignment decorators.
> lhs = rhs
> would be equivalent to
> lhs = decorator('lhs', rhs)
A recurring question on python-list is "how do I find out the name of
my variable?" and the recurring answer is "why does it matter?" or
"what do you mean by _the_ name?"
In general I'm wary of adding features who's only purpose is making
DSLs easier to write in pure python. function/class decorators are
currently just syntactic sugar for things you could already do.
Speaking of deocrators, after this change what would function and
class decorators look like? Currently the identity decorator is
Would the new syntax change that to
def decorator(name, ob):
? or change it to that only for assignments but not classes and functions?
More information about the Python-ideas