[Python-ideas] Augmented assignment syntax for objects.

Erik python at lucidity.plus.com
Tue Apr 25 18:14:08 EDT 2017


On 25/04/17 02:15, Chris Angelico wrote:
> Bikeshedding: Your example looks a lot more like tuple assignment than
> multiple assignment.

Well, originally, I thought it was just the spelling-the-same-name-twice 
thing that irritated me and I was just going to suggest a single 
assignment version like:

   self .= foo
   self .= bar

Then I thought that this is similar to importing (referencing an object 
from one namespace in another under the same name). In that scenario, 
instead of:

   from other import foo
   from other import bar

we have:

   from other import foo, bar

That's where the comma-separated idea came from, and I understand it 
looks like a tuple (which is why I explicitly mentioned that) but it 
does in the import syntax too ;)

The single argument version (though it doesn't help with vertical space) 
still reads better to me for the same reason that augmented assignment 
is clearer - there is no need to mentally parse that the same name is 
being used on both sides of the assignment because it's only spelled once.

> self .= foo .= bar .= baz .= spam .= ham

Thanks for being the only person so far to understand that I don't 
necessarily want to bind ALL of the __init__ parameters to the object, 
just the ones I explicitly reference, but I'm not convinced by this 
suggestion. In chained assignment the thing on the RHS is bound to each 
name to the left of it and that is really not happening here.

> The trouble is that this syntax is really only going to be used inside
> __init__.

Even if that was true, who ever writes one of those? :D

E.


More information about the Python-ideas mailing list