> It's late to raise this,
By months, yes ;-)
> but what exactly are the objections to the syntax
> expr -> name # or variations such as expr
> instead of
> name := expr
> The PEP mentions that this syntax does not have a problem
> does, but does not list any downsides of it.
My guess: it probably strikes too many as "excessive
novelty", These are assignment expressions. Python's
assignment statements put the target at the left. Why change
that? ":=" is used for assignment in many more other
languages than "->" is. Why fight that?
> It conforms to left-to-right evaluation, where name:=expr
? Only "expr" is evaluated, so left-to-right seems irrelevant
here. The "evaluation" of a simple name as a binding target
is a no-op (no code is generated). If you really do see this
as a wart anyway, then it's positively a Good Thing that it's
exactly the same "wart" as in Python's assignment statements.
> It (I would argue) reduces the asymmetry of the first use
> sub-expression in cases such as
> [ ( (f(x) -> y)**2, y**3, y**4) for x in iterable
> [ ( (y := f(x))**2, y**3, y**4) for x in iterable ]
> because the first "y" is closer to the way it is used,
The first form reads a little better to me too, but not a lot
better. The problem I have with variations of this example on
its own (which comes up surprisingly often with minor changes)
is that it's clearer spelled today via
[(y**2, y**3, y**4) for y in map(f, iterable)]
Spelling that with either form of assignment expression reads
significantly worse than that to my eyes
But more importantly, it's expected
that assignment expressions will be used _most_ often to make
some common `if` and `while` patterns briefer. Hardly all.
Our eyes are already trained to "look at the far right end"
for the value being tested, and, e.g.,
while data := sock.recv():
preserves that. Especially in code
that doesn't _always_ use assignment expressions in such
contexts (which is likely all significant blobs of code), it
would be visually jarring to have to "sometimes look in the
middle instead" to extract the important part of:
while sockrecv() -> data:
"Look to the left for the name, look to the right for the
value" is the rule for assignment statements, assignment
expressions, and `for` loop targets.
But there's no "QED" here because this isn't a deductive
science. The final answer is "because that's what Guido
liked best" ;-)