Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95912 > unrolled thread

Re: packing unpacking depends on order.

Started byrandom832@fastmail.us
First post2015-09-02 21:17 -0400
Last post2015-09-02 21:17 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: packing unpacking depends on order. random832@fastmail.us - 2015-09-02 21:17 -0400

#95912 — Re: packing unpacking depends on order.

Fromrandom832@fastmail.us
Date2015-09-02 21:17 -0400
SubjectRe: packing unpacking depends on order.
Message-ID<mailman.49.1441243048.8327.python-list@python.org>
On Wed, Sep 2, 2015, at 13:26, Sven R. Kunze wrote:
> I agree as well. First evaluate the right side, then assign it to the 
> left side at once.

The behavior, if it's *not* "first evaluating the right side", is
indistinguishable from it by this test. Assigning the RHS of each case
to a separate list yields the same result:

>>> a, b = [1, 2, 3, 4, 5], 1
>>> abb = a[b], b
>>> bab = b, a[b]
>>> b, a[b] = abb
>>> a
[1, 2, 1, 4, 5]
>>> a, b = [1, 2, 3, 4, 5], 1
>>> a[b], b = bab
>>> a
[1, 1, 3, 4, 5]

What's happening is this:

>>> abb = a[b], b # 2, 1
>>> bab = b, a[b] # 1, 2
then
>>> b, a[b] = abb # b = 2; a[2] = 1
or
>>> a[b], b = bab # a[1] = 1; b = 2

The question is what does "assign it to the left side at once" even
*mean* in the presence of subscripts? Build up a list of
object-subscript pairs (evaluating all the subscripts, including if any
may have side effects) before executing any __setitem__?

Why is the right side evaluated first? Why not build up this "assignment
destination list" first, before evaluating the right side? They wouldn't
be distinguished by this test, since the RHS has no side effects, but
it'd be easy enough to devise such a test case.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web