[Python-ideas] Inline assignments using "given" clauses

Jacco van Dorp j.van.dorp at deonet.nl
Mon May 14 04:12:15 EDT 2018


I think we're approaching this from the wrong direction.

My point is, expression assignments dont have the complex case as
purpose - most coders wont try to maximize line information density.
If you're doing magic, you might as well spell it out over multiple
lines, because neither := nor given will be readable.

However, in the simple case, it does matter a lot - and there := beats
out given by a mile.

If you're breaking your lines to avoid line length violations, you
might as well put your assignments on a separate lines first. Im
inclined to argue that if assignment expressions of any form forces to
you make a multi-line statement, you're doing it wrong. (in the vast
majority of cases).

Consider it like the ternary operator - good to compact simple
constructs, but while you can use it for black magic, you probably
shouldn't.

How about we just explicitly advice to keep it simple, stupid, and
update PEP 8 to state that if assignment expressions take you to
multi-line, split of the assignment and use statements instead.

(truth be told, the general while (assignment expression isn't as
clear cut as if-uses, but I think the idea holds.))

Jacco


More information about the Python-ideas mailing list