Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'interpreter': 0.05; 'exception,': 0.07; '>>>>': 0.09; 'failing': 0.09; 'mutable': 0.09; 'tuple': 0.09; 'tuple.': 0.09; '"+="': 0.16; 'awesome.': 0.16; 'both.': 0.16; 'element,': 0.16; 'elsewhere,': 0.16; 'imho,': 0.16; 'intended.': 0.16; 'subject:copy': 0.16; 'suppose)': 0.16; 'wrote:': 0.16; 'wed,': 0.17; 'jan': 0.19; 'appears': 0.19; '(most': 0.21; 'feb': 0.22; 'header:In-Reply- To:1': 0.22; '-0500': 0.23; 'interpreted': 0.23; "shouldn't": 0.23; 'traceback': 0.24; 'sender:addr:gmail.com': 0.25; 'pm,': 0.26; 'all,': 0.27; 'says': 0.27; 'not.': 0.28; 'lists': 0.28; 'example': 0.28; '(and': 0.29; 'fri,': 0.30; 'object.': 0.30; 'typeerror:': 0.30; 'pretty': 0.30; 'thu,': 0.32; 'actually': 0.32; 'does': 0.32; 'objects': 0.32; "can't": 0.32; 'to:addr :python-list': 0.33; 'object': 0.33; 'there': 0.33; 'normally': 0.34; 'right,': 0.34; 'assignment': 0.34; 'last):': 0.34; 'received:209.85.160.46': 0.35; 'received:mail- pw0-f46.google.com': 0.35; 'received:209.85.160': 0.35; 'file': 0.35; '(by': 0.36; 'element': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'another': 0.37; 'steven': 0.38; 'received:209.85': 0.38; 'think': 0.38; 'sense': 0.39; 'received:209': 0.39; 'doing': 0.39; 'subject:: ': 0.39; 'did': 0.39; 'to:addr:python.org': 0.40; 'received:203': 0.60; 'more': 0.61; 'john': 0.62; 'applying': 0.62; 'header:Message-Id:1': 0.62; 'fact,': 0.63; 'failure': 0.74; '-0800': 0.84; 'subject:write': 0.84; 'worthy': 0.84; 'received:home': 0.91; 'conclude': 0.95; 'surprise': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:date:from:to:subject:message-id:in-reply-to:references :x-mailer:mime-version:content-type:content-transfer-encoding; bh=JbzLp4Le+lZZDpf00zzC9NqjIsorKEDwgPvbNjI8DyM=; b=J+Ky3Wbi9QvRKfzcll0YDV48DFfNasesHpKK7WAwETXlZ9H6U/syBUSptyPcm/0FBB g1LIuBB/9XZmop9jaf5fJAJxfRS7Ir4I3qIhPXxtdS2XRSuo8pYXu/+aURslxdy5vT3v kWF9tLBPSpZ14a/GCn1giZeF775wg1yzV1pi4= Sender: "John O'Hagan" Date: Thu, 2 Feb 2012 19:11:53 +1100 From: John O'Hagan To: python-list@python.org Subject: Re: copy on write In-Reply-To: References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <4f102bd0$0$29999$c3e8da3$5496439d@news.astraweb.com> <4F107AAF.5000600@stoneleaf.us> <20120202141812.649c31d832bb15bd899eb952@johnohagan.com> X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.8; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328170324 news.xs4all.nl 6898 [2001:888:2000:d::a6]:41170 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19779 On Thu, 2 Feb 2012 01:34:48 -0500 Devin Jeanpierre wrote: > On Wed, Feb 1, 2012 at 10:18 PM, John O'Hagan > wrote: > > On Fri, 13 Jan 2012 10:40:47 -0800 > > Ethan Furman wrote: > > > >> Steven D'Aprano wrote: > >> > Normally this is harmless, but there is one interesting little > >> > glitch you can get: > >> > > >> >>>> t = ('a', [23]) > >> >>>> t[1] += [42] > >> > Traceback (most recent call last): > >> >   File "", line 1, in > >> > TypeError: 'tuple' object does not support item assignment > >> >>>> t > >> > ('a', [23, 42]) > > > > IMHO, this is worthy of bug-hood: shouldn't we be able to conclude > > from the TypeError that the assignment failed? > > It did fail. The mutation did not. You're right, in fact, for me the surprise is that "t[1] +=" is interpreted as an assignment at all, given that for lists (and other mutable objects which use "+=") it is a mutation. Although as Steven says elsewhere, it actually is an assignment, but one which ends up reassigning to the same object. But it shouldn't be both. I can't think of another example of (what appears to be but is not) a single operation failing with an exception, but still doing exactly what you intended. > > I can't think of any way out of this misleadingness, although if you > can that would be pretty awesome. In the case above, the failure of the assignment is of no consequence. I think it would make more sense if applying "+=" to a tuple element were treated (by the interpreter I suppose) only on the merits of the element, and not as an assignment to the tuple. John