Path: csiph.com!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'attributes': 0.07; 'expressions': 0.07; 'assigning': 0.09; 'bindings': 0.09; 'brackets': 0.09; ':-)': 0.12; '*should*': 0.16; '7:51': 0.16; 'assignments': 0.16; 'assignments,': 0.16; 'assignments.': 0.16; 'attributes,': 0.16; 'lhs': 0.16; 'rhs': 0.16; 'stored.': 0.16; 'wrote:': 0.16; '2015': 0.20; 'algorithm': 0.20; 'sep': 0.22; 'references': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'right.': 0.27; 'least': 0.27; 'question': 0.27; 'message- id:@mail.gmail.com': 0.27; 'collecting': 0.27; 'values': 0.28; 'about.': 0.29; 'behaviour': 0.29; 'asked': 0.29; "i'm": 0.30; 'e.g.': 0.30; 'error.': 0.31; 'skip:_ 10': 0.32; 'done,': 0.33; 'gives': 0.35; 'received:google.com': 0.35; 'exist': 0.35; 'supports': 0.35; 'but': 0.36; 'there': 0.36; '(i.e.': 0.36; 'cases': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'side': 0.62; 'matter': 0.63; 'different': 0.63; 'results': 0.66; 'today.': 0.67; 'evaluate': 0.72; 'square': 0.76; 'to:name:python': 0.84; 'effects,': 0.91; 'effects.': 0.91; 'items,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=OGEfY2z19u1h5Q5jNNDJXu2Pjny0ovTmJk+ORXP2tzs=; b=Hi9+ns9YPZZPJtpL/ulG3HZ0DNo5ouBJcHIbPf3KQfIMJcEb/mj44ipzrT8/qUEuYx gOJ3TZtlwOJozU6wtt1Dk8tetC1plyDtMmeDgLFV1eg5UUPr5+Zf36WZkpxiKQgXCqMZ g3vkD9n3DhgaAiDpLldKjBKKAJUJx+kUGmLnMlYp1s4Qm2/01bVqIftSZENJuvLx0pSy qoqenuB6gX1fm23/QIvAMXA+7nVV/PeLp7QsKInFMsLNsQox+2QxJDB5TQ0jCsX8H8bG iSSy8YJM6QH4s0NwcgI3e1D2PaRubb/lKnf+yPvZUkia3JyZp+5q5MCYcEBFGDIv710Y IIoQ== X-Received: by 10.170.203.197 with SMTP id u188mr8181526yke.113.1441251198784; Wed, 02 Sep 2015 20:33:18 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <55e7a652$0$1672$c3e8da3$5496439d@news.astraweb.com> References: <55E6C904.3020602@rece.vub.ac.be> <55e7a652$0$1672$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Wed, 2 Sep 2015 21:32:39 -0600 Subject: Re: packing unpacking depends on order. To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441251201 news.xs4all.nl 23749 [2001:888:2000:d::a6]:35033 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95917 On Sep 2, 2015 7:51 PM, "Steven D'Aprano" wrote: > > What's the alternative? I asked this question earlier, and got no answer -- > apparently at least three people prefer behaviour that they cannot explain > how to get the results they want :-) > > As far as I am concerned, having both of these: > > b, a[b] = a[b], b > a[b], b = b, a[b] > > result in the same bindings is not only hard to implement, but hard to > explain and hard to think about. Try to write an algorithm that gives the > result you want, I don't think it's really all that difficult. 1) Evaluate the RHS from left to right as is already done, collecting the values to be assigned. 2) Evaluate the LHS from left to right. Note there are only three different types of assignments: assignments to names, assignments to attributes (i.e. using __setattr__), and assignments to items (i.e. using __setitem__). a) For assignments to names, there is nothing to evaluate. b) For assignments to attributes, the expression to the left of the . must be evaluated and stored. c) For assignments to items, the expression before the square brackets and the expression inside the square brackets must be evaluated (probably in that order, although it doesn't much matter as long as it's consistent) and stored. 3) Perform the assignments, again from left to right. There can still be ordering effects, e.g. if you do a, b.c = d, e and b's __setattr__ references a, or if one of the expressions has side effects. The same is also true on the RHS, as it is today. I'm not really concerned with that possibility. > one which supports all the cases including the case where > one or both of a and b don't exist prior to the assignments. That's a red herring. If either a or b don't exist prior to the assignments, then the result of assigning to a[b] *should* be an error.