Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'operator': 0.04; '>>>>': 0.09; 'generators': 0.09; 'tuple': 0.09; 'types:': 0.09; '~ethan~': 0.09; 'converting': 0.15; "'w',": 0.16; '(1,': 0.16; 'imho,': 0.16; 'imo,': 0.16; 'subject:copy': 0.16; 'succeed,': 0.16; 'tuples,': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'jan': 0.19; 'possibly': 0.19; '(most': 0.21; 'header:In-Reply-To:1': 0.22; 'operand': 0.23; "shouldn't": 0.23; 'traceback': 0.24; 'sender:addr:gmail.com': 0.25; 'lists': 0.28; 'fri,': 0.30; 'implicitly': 0.30; 'typeerror:': 0.30; 'does': 0.32; 'objects': 0.32; 'list': 0.32; 'to:addr:python-list': 0.33; 'object': 0.33; 'there': 0.33; 'normally': 0.34; 'list.': 0.34; 'assignment': 0.34; 'last):': 0.34; '(not': 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; 'charset:us-ascii': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'happens': 0.37; 'could': 0.37; 'steven': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'either': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'range': 0.60; 'received:203': 0.60; 'more': 0.61; 'john': 0.62; 'header:Message-Id:1': 0.62; 'special': 0.67; '-0800': 0.84; 'sets,': 0.84; 'subject:write': 0.84; 'worthy': 0.84; '-->': 0.91; 'received:home': 0.91; 'conclude': 0.95; 'treatment': 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=2DafcguR3lqxQJbVoWCD7IStUy/G5haH7N37y0gtmVE=; b=npQW+G9TX0p0eE0mVWgcD+AwdmQDXolUdfQ7rVkXPEHp1mF0heqGOErGIh4j8LiqRr g5VkCdv0hyQI2lAJdkEPXT0cbBxjmqo2X17T5SBkjgCqruFiwQdOUzx29rS6F4G5vewk qSxZqXG/pE+DcITcGiYMvkqeI6u1Nkku4hc+U= Sender: "John O'Hagan" Date: Thu, 2 Feb 2012 14:18:12 +1100 From: John O'Hagan To: python-list@python.org Subject: Re: copy on write In-Reply-To: <4F107AAF.5000600@stoneleaf.us> References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <4f102bd0$0$29999$c3e8da3$5496439d@news.astraweb.com> <4F107AAF.5000600@stoneleaf.us> X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.8; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328152702 news.xs4all.nl 6847 [2001:888:2000:d::a6]:41398 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19765 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? > There is one other glitch, and possibly my only complaint: > > --> a = [1, 2, 3] > --> b = 'hello, world' > --> a = a + b > Traceback (most recent call last): > File "", line 1, in > TypeError: can only concatenate list (not "str") to list > --> a += b > --> a > [1, 2, 3, 'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'] > > IMO, either both + and += should succeed, or both should fail. > > ~Ethan~ This also happens for tuples, sets, generators and range objects (probably any iterable), AFAIK only when the left operand is a list. Do lists get special treatment in terms of implicitly converting the right-hand operand? The behaviour of the "in-place" operator could be more consistent across types: >>> a=[1,2] >>> a+=(3,4) >>> a [1, 2, 3, 4] >>> a=(1,2) >>> a+=(3,4) >>> a (1, 2, 3, 4) >>> a=(1,2) >>> a+=[3,4] Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate tuple (not "list") to tuple John