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

Ethan Furman ethan at stoneleaf.us
Fri Mar 4 20:06:23 CET 2011

Greg Ewing wrote:
> Ethan Furman wrote:
>> Do we even need the def?
>> class Person(object):
>>     name    as Str()
>>     address as Str()
> I think that would be paring it down a bit foo far -- there's
> not much left to suggest that a name is being bound. At
> least 'def' implies that something is being defined rather
> than just referred to.
>> we could also add more magic and make the assigned name an available 
>> attribute to the function when it's called.
> I don't understand. Attribute of what?

Not entirely sure...  maybe something along the lines of __name__, etc., 
like __var_name__, which is either the target of the lhs, or None.

class Person():
     name = Str()
     address = Str()

def Str():
     whatever = __var_name__  # 'name' in first call, 'address' in second


More information about the Python-ideas mailing list