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

Larry Hastings larry at hastings.org
Fri Mar 4 10:17:11 CET 2011


On 03/03/2011 05:59 PM, Raymond Hettinger discussed a possible language 
change (but later made it clear he wasn't actually proposing it):
> If there were going to be only one syntax change for Python 3.3, why 
> not use it for something that adds a lot more expressive power:
>
>     x = a!name      #  x = getattr(a, name)
>
> That bit of syntactic sugar might greatly expand our minds when it 
> comes to dynamically creating and accessing attributes.

We ran that up the ol' flagpole back in February 2007:

    http://mail.python.org/pipermail/python-dev/2007-February/071040.html

It was ultimately rejected:

    http://mail.python.org/pipermail/python-dev/2007-February/071107.html

Dynamic attribute access is rare in real-world code.  So folks who need 
it are currently well-served by getattr().  I think it's a bad idea to 
add new syntax that adds no new functionality and which we already know 
will be rarely used.  Why manufacture dusty corners of the language?

If one felt getattr() was too clumsy or ugly, one could use the 
attrview() class as proposed in that thread:

    aview = attrview(a)
    aview[name] # getattr(a, name)

That's very pretty and requires no new syntax.

As Raymond himself said just a few messages ago:
> If you're going to change the language syntax, make it count and do something cool :-)


/larry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110304/aa6aa7eb/attachment.html>


More information about the Python-ideas mailing list