* *<target> = <value>* is an assignment with no return value
* *(<target> = <value>)* is an assignment with a returned value
So now '=' is always an assignment, it is an assignment with extra
semantics depending on surrounding syntax.
As discussed previously by others on this exact proposals, you now have
the issue of confusion when using keyword arguments : *my_func(a = b)*
: clearly that is a call to `my_func' where argument a has the value of
b, but if you want to do an assigment expression when calling the
function you now have to do *my_func((a=b)) -* which frankly looks messy
in my opinion; you get the same issue when you are wanting to do
assignment expressions in tuples.
Using a different operator for assignments which return values avoids
the messy potentially multiple level brackets, and means that the
semantics of an operator depends only on that operator and not on syntax
elements before and after it.
--
--
Anthony Flury
email : *Anthon...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*
In JavaScript there's a new backticks syntax for string—their variant
of f-strings. I'm seeing a lot of JS coders that use backticks
everywhere, regardless if there's formatting in them or not. The
result is that some JS code in popular libraries has now *three*
different string literal syntaxes separated by one line of code. It
looks weird. I expect to see something similar in Python code if we
adapt ':='. I don't think the language will benefit from this.
FWIW I'm fine with keeping the status quo and not adding new syntax at all.
Yury
Just because you wrap a set of character in parens doesn't mean that you
wont potentially mistype what you should type inside the parens. The
failure mode of in C :
if (a = 3)
do_something_with_a(a);
Is Incredibly common even with very experienced developers - so much so
that most linters flag it as a likely error, and I think gcc has an
option to flag it as a warning - even though it is valid and very
occasionally it is useful.
Also many developers who come to Python from languages such as C will
still place parens around conditionals - this means that a typo which
will cause a Syntax Error in current versions, but would cause a
potentially subtle bug under your implementation (unless you maintain
the rule that you can't rebind currently bound names - which renders the
whole idea useless in loops (as already discussed at length).
I also still can't think of a single other Python construct where the
semantics of an operator are explicitly modified by syntaxtic elements
outside the operator. For mathematical operators, the surrounding parens
modifies the grouping of the operators but not the semantics (* means *,
it is just the operands which potentially change).
You could argue that your proposal overloads the semantics of the parens
(similar to how braces are overloaded to implement dictionaries and set
literals), but I don't think that overloading the semantics of parens is
good idea.
If Python is going to do assignment expressions we shouldn't overload
parens in my opinion - we should have a separate operator - doing this
avoids needing to exclude rebinding, and makes such expressions
considerably more useful.
--
Anthony Flury
email : *Anthon...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*
On Tue, Apr 24, 2018 at 03:54:30PM -0700, Guido van Rossum wrote:
> We should really take this back to python-ideas at this point.
Please no :-(