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

Larry Hastings larry at hastings.org
Tue Mar 8 02:24:49 CET 2011

On 03/07/2011 08:08 PM, Chris Kaynor wrote:
> You seemed to have missed the example of:
> lhs = @dec1 123
> which would produce
> dec1(classobject, 'lhs', 123)
> correct?

No, that was deliberately not part of my proposal.  My thinking: most of 
the time, this will be used in class scope for creating objects that 
have their own reasonable default values.  Why force people to type in a 
default value that 99% of the time you don't care about?  Allowing you 
to override this default value would be done by making the decorator 
callable and return a callable, like

    lhs = @dec1(123)

Also, I thought the "@dec1 123" style just looked too weird.  I admit it 
isn't that much weirder than what I already proposed.

However, if there are great uses for assignment decorators outside class 
scope, perhaps we need this original rhs.  Other folks have pointed 
out--what does something like this mean?

    c = Class()
    c.member = @dec

Does dec get 'c.member'?  Is this useful for anything?  Shall we narrow 
the use of assignment decorators to just class scope?

On 03/07/2011 08:08 PM, Joao S. O. Bueno wrote:
> What you are calling "classobject" simply don't exist at this stage
> wen creating a new class.

Toldja it probably wasn't a good idea!

> This is Python, where function calls has "(" .

I'm not sure if this is part of a default signature or a rejoinder to 
me.  If the latter, let me point out that class/function decorators are 
already function calls without parentheses; it seems natural enough that 
assignment decorators would similarly lack them.


More information about the Python-ideas mailing list