[issue42295] Error should be flagged if Walrus operator is used for multiple assigment
Batuhan Taskaya
report at bugs.python.org
Mon Nov 9 05:54:43 EST 2020
Batuhan Taskaya <isidentical at gmail.com> added the comment:
Due to the precedence of the walrus operator, it is not actually a multiple assignment but rather a tuple of 3 elements with one being the value of the assignment expression.
$ python -m ast
(a, b := 3, 4)
Module(
body=[
Expr(
value=Tuple(
elts=[
Name(id='a', ctx=Load()),
NamedExpr(
target=Name(id='b', ctx=Store()),
value=Constant(value=3)),
Constant(value=4)],
ctx=Load()))],
type_ignores=[])
In this case, it creates a tuple with loading the name `a` from the current scope, using the value of the 3 and also assigning 3 to the b, and loading constant 4.
So basically (a, b := 3, 4) is actually (a, (b := 3), 4)
----------
nosy: +BTaskaya
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42295>
_______________________________________
More information about the Python-bugs-list
mailing list