Python 3000 idea: reversing the order of chained assignments
steve at holdenweb.com
Thu Mar 22 10:55:03 CET 2007
Duncan Booth wrote:
> "Virgil Dupras" <hardcoded.software at gmail.com> wrote:
>> I think I see what Marcin means. The 'node' is changed too fast in the
>> chain, and next is assigned to 'nextnode' instead of being assigned to
> I can see why Marcin was confused. Many other languages assignment is an
> expression, so a=b=c is simply a=(b=c). In Python it isn't an expression,
> the chained assignment is a specific part of the syntax, so (as with
> chained comparisons) the semantics may be surprising to the uninitiated.
> As a matter of interest do PyLint or PyChecker check for this situation
> (chained assignment where the target of an assignment is also a
> subexpression of a later assignment)?
Where's the published syntax for chained assignment?
> Also it may be worth noting that unpacking has a similar behaviour:
> node, node.next = nextnode, nextnode
> has the same result as the chained assignment: the RHS is a tuple and is
> fully evaluated before the assignment, but the LHS is not a tuple and the
> assignment happens strictly left to right with each assignment fully
> completed before proceeding to the next one.
Well that is explained (albeit badly) in the reference manual:
"""An assignment statement evaluates the expression list (remember that
this can be a single expression or a comma-separated list, the latter
yielding a tuple) and assigns the single resulting object to each of the
target lists, from left to right."""
That wording appears to be a rather bad mix of factoids from unpacking
and chained assignment. Is it just me, or does this whole section need a
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
More information about the Python-list