Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'explicitly': 0.05; 'assignment': 0.07; 'modified': 0.07; '"if': 0.09; 'assigning': 0.09; 'augmented': 0.09; 'method,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'similar,': 0.09; 'target,': 0.09; 'jan': 0.12; '"an': 0.16; 'clause,': 0.16; 'implies': 0.16; 'in-place': 0.16; 'in-place,': 0.16; 'it".': 0.16; 'operator.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'rewritten': 0.16; 'language': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'possible,': 0.19; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'chapter': 0.26; 'equivalent': 0.26; 'second': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'url:bugs': 0.29; 'operators': 0.31; 'lists': 0.32; 'extend': 0.32; 'says': 0.33; 'url:python': 0.33; 'actual': 0.34; 'equal': 0.35; 'but': 0.35; 'there': 0.35; 'done': 0.36; 'url:org': 0.36; 'should': 0.36; 'list': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'expression': 0.60; 'ian': 0.60; 'new': 0.61; 'received:173': 0.61; 'fact,': 0.69; 'guaranteed': 0.75; "class's": 0.84; 'odds': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Tuples and immutability Date: Sun, 09 Mar 2014 19:00:16 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394406046 news.xs4all.nl 2833 [2001:888:2000:d::a6]:40607 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68105 On 3/9/2014 6:03 PM, Gregory Ewing wrote: > Ian Kelly wrote: >> In my view the second one is wrong. a += b should be understood as >> being equivalent to a = a + b, but with the *possible* and by no means >> guaranteed optimization that the operation may be performed in-place. > > This interpretation is at odds with the Language Reference, > section 6.2.1, Augmented Assignment Statements: > > "An augmented assignment expression like x += 1 can be rewritten as x = > x + 1 to > achieve a similar, but not exactly equal effect... when possible, the > actual operation is performed > in-place, meaning that rather than creating a new object and assigning > that to > the target, the old object is modified instead." > > Note that it says "when possible", not "if the implementation > feels like it". > >> In fact, if you read the documentation for lists, you may notice that >> while they clearly cover the + operator and the extend method, they do >> not explicitly document the list class's += operator. > > The "when possible" clause, together with the fact that lists > are mutable, implies that it *will* be done in-place. There > is no need to document all the in-place operators explicitly > for every type. The discussion of .__iop__ in the datamodel chapter was just revised slightly. http://bugs.python.org/issue19953 -- Terry Jan Reedy