packing unpacking depends on order.

Antoon Pardon antoon.pardon at
Wed Sep 2 15:59:26 CEST 2015

Op 02-09-15 om 14:45 schreef Chris Angelico:
> On Wed, Sep 2, 2015 at 10:26 PM, Steven D'Aprano <steve at> wrote:
>>> I think I understand how it gets these results
>>> but I'm not really happy with them. I think python
>>> should give the second result in both cases.
>> Apart from breaking backwards compatibility, how would you implement such a
>> thing? A simple left-to-right assignment rule is easy to implement and easy
>> to understand even when the targets depend on each other.
> I don't think this is really a question of implementation - it's a
> design question of "should".
> The current behaviour is reasonably sane.

Yes it is reasonable sane, I just think the alternative would be saner.

>  But if you're confused by
> it, there's a simple solution: Don't reference the same "thing" more
> than once on the LHS.

That is rather extreme. It would mean we avoid the following:

a[i], b[i] = b[i], a[i] # references i twice on the LHS.
a[i], a[j] = a[j], a[i] # references a twice on the LHS.

I think a better rule would be: Don't reference and bind
the same "thing" on the LHS.

Antoon Pardon

More information about the Python-list mailing list