[Python-Dev] PEP 572: Do we really need a ":" in ":="?
Alexander Belopolsky
alexander.belopolsky at gmail.com
Thu Jul 5 19:42:34 EDT 2018
I wish I had more time to make my case, but with the PEP 572 pronouncement
imminent, let me make an attempt to save Python from having two assignment
operators.
I've re-read the PEP, and honestly I am warming up to the idea of allowing
a limited form of assignment in expressions. It looks like in the current
form, the PEP supports only well-motivated cases where the return value of
the assignment expression is non-controversial. It also appears that there
are no cases where = can be substituted for := and not cause a syntax
error. This means that ":" in ":=" is strictly redundant.
Interestingly, Python already has a precedent for using redundant ":" - the
line-ending ":" in various statements is redundant, but it is helpful both
when reading and writing the code.
On the other hand, ':' in ':=' looks like an unnecessary embellishment.
When we use ':=', we already know that we are inside an expression and
being inside an expression is an obvious context for the reader, the writer
and the interpreter.
I also believe, allowing a limited form of assignment in expressions is a
simpler story to tell to the existing users than an introduction of a new
operator that is somewhat like '=', but cannot be used where you currently
use '=' and only in places where '=' is currently prohibited.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180705/4629c5fb/attachment.html>
More information about the Python-Dev
mailing list