Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19820

Re: copy on write

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <johnmohagan@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'context': 0.04; 'omit': 0.07; 'terry': 0.07; 'modifies': 0.09; 'object?': 0.09; 'operator,': 0.09; 'am,': 0.12; '"+="': 0.16; '203': 0.16; 'int.': 0.16; 'operand:': 0.16; 'pydev': 0.16; 'read:': 0.16; 'reedy': 0.16; 'subject:copy': 0.16; 'wrote:': 0.16; "wouldn't": 0.17; '>>>': 0.18; 'phrase': 0.18; 'say,': 0.19; 'seems': 0.19; '(most': 0.21; 'maybe': 0.21; 'discussion': 0.21; 'feb': 0.22; 'header:In- Reply-To:1': 0.22; '-0500': 0.23; 'pep': 0.23; "shouldn't": 0.23; 'object,': 0.24; 'traceback': 0.24; 'sender:addr:gmail.com': 0.25; 'creating': 0.25; '(in': 0.26; '"the': 0.26; 'function': 0.27; 'not.': 0.28; 'effect': 0.28; 'discussing': 0.28; 'true,': 0.28; '(and': 0.29; 'augmented': 0.30; 'list).': 0.30; 'semantics': 0.30; 'typeerror:': 0.30; 'quite': 0.31; 'suggested': 0.32; 'thu,': 0.32; 'does': 0.32; 'that,': 0.32; 'list': 0.32; 'idea': 0.32; 'to:addr:python-list': 0.33; 'object': 0.33; 'there': 0.33; 'this.': 0.33; "we're": 0.34; 'assignment': 0.34; 'last):': 0.34; 'widespread': 0.34; 'operations': 0.34; 'probably': 0.35; 'something': 0.35; 'received:209.85.160.46': 0.35; 'received:mail- pw0-f46.google.com': 0.35; 'received:209.85.160': 0.35; 'response': 0.35; 'file': 0.35; 'uses': 0.36; '"you': 0.36; 'charset:us-ascii': 0.36; 'reference': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'could': 0.37; 'some': 0.38; 'received:209.85': 0.38; 'put': 0.38; 'think': 0.38; 'sometimes': 0.38; 'should': 0.38; 'either': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'one,': 0.40; 'type': 0.60; 'received:203': 0.60; 'types': 0.61; 'john': 0.62; 'header:Message-Id:1': 0.62; 'was:': 0.67; 'exact': 0.68; 'succeed': 0.73; 'with,': 0.73; 'introduced.': 0.84; 'subject:write': 0.84; 'received:home': 0.91; 'shocked': 0.91
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=SCvZDDIMad379amPY9GRvfmT5WCWQ81IqvyhEmk8ZzE=; b=pzreRhloNFfT+/dGvBIyv84DL/7JCfKwRafo3BIN7AOHFPG4kLa16SIdsYa017mhVp PqDPCOjcbE9kHwxgIzw7ZTO9uUw1A6p5PpJGMVBj7mXqT1SLQV8+Rg//e8TgaSFbIJx9 G4/xJXVO17sxmphzNAoAWJJ9Av6a2ncODrKnw=
Sender "John O'Hagan" <johnmohagan@gmail.com>
Date Fri, 3 Feb 2012 14:08:06 +1100
From John O'Hagan <research@johnohagan.com>
To python-list@python.org
Subject Re: copy on write
In-Reply-To <jgegti$c9f$1@dough.gmane.org>
References <mailman.4709.1326455724.27778.python-list@python.org> <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <mailman.4712.1326457859.27778.python-list@python.org> <4f102bd0$0$29999$c3e8da3$5496439d@news.astraweb.com> <4F107AAF.5000600@stoneleaf.us> <20120202141812.649c31d832bb15bd899eb952@johnohagan.com> <CABicbJLKh1Ticp=EDPBWTwESTn5HkDQsopTCWrYH-hY6isOgxQ@mail.gmail.com> <mailman.5348.1328170324.27778.python-list@python.org> <4f2a5478$0$29895$c3e8da3$5496439d@news.astraweb.com> <20120203011748.592f060f32ac79d450a2ca8d@johnohagan.com> <jgegti$c9f$1@dough.gmane.org>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5388.1328238503.27778.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328238503 news.xs4all.nl 6919 [2001:888:2000:d::a6]:34689
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19820

Show key headers only | View raw


On Thu, 02 Feb 2012 12:25:00 -0500
Terry Reedy <tjreedy@udel.edu> wrote:

> On 2/2/2012 9:17 AM, John O'Hagan wrote:
> 
> > It's not so much about the type of x but that of x[1]. Wouldn't it
> > be possible to omit the assignment simply if the object referred to
> > by x[1] uses "+=" without creating a new object? That way,
> > some_tuple[i] += y will succeed if some_tuple[i] is a list but not
> > with, say, an int. That seems reasonable to me.
> 
> There was considerable discussion of the exact semantics of augmented 
> operations when they were introduced. I do not remember if that 
> particular idea was suggested (and rejected) or not. You could try to 
> look at the PEP, if there is one, or the dicussion ( probably on
> pydev list).
> 

I think we're 12 years late on this one. It's PEP 203 from 2000 and the key phrase was:

"The in-place function should always return a new reference, either
to the old `x' object if the operation was indeed performed
in-place, or to a new object."

If this had read:

"The in-place function should return a reference to a new object
if the operation was not performed in-place."

or something like that, we wouldn't be discussing this.

The discussion on py-dev at the time was quite limited but there was some lively debate on this list the following year (in the context of widespread controversy over new-fangled features which also included list comprehensions and generators), to which the BDFL's response was:

"You shouldn't think "+= is confusing because sometimes it modifies an
object and sometimes it does".  Gee, there are lots of places where
something that's *spelled* the same has a different effect depending
on the object types involved."


That's true, but I don't think there should be a different effect depending on what _name_ we use for an operand:

>>> t=([],)
>>> l=t[0]
>>> l is t[0]
True
>>> l+=[1]
>>> t
([1],)
>>> t[0]+=[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> t
([1, 1],)
>>> l is t[0]
True

Same object, same operator, different name, different outcome. Maybe that was obvious from the foregoing discussion, but it shocked me when put that way.

John

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

copy on write Eduardo Suarez-Santana <esuarez@itccanarias.org> - 2012-01-13 11:33 +0000
  Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-13 12:10 +0000
    Re: copy on write Chris Angelico <rosuav@gmail.com> - 2012-01-13 23:30 +1100
      Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-13 13:04 +0000
        Re: copy on write Ethan Furman <ethan@stoneleaf.us> - 2012-01-13 10:40 -0800
          Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-13 14:26 -0800
          Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-13 14:26 -0800
        Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-02 14:18 +1100
        Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-02-02 01:34 -0500
        Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-02 19:11 +1100
          Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 09:16 +0000
            Re: copy on write Hrvoje Niksic <hniksic@xemacs.org> - 2012-02-02 11:53 +0100
              Re: copy on write MRAB <python@mrabarnett.plus.com> - 2012-02-02 16:28 +0000
              Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-02-02 12:21 -0500
            Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-03 01:17 +1100
            Re: copy on write Terry Reedy <tjreedy@udel.edu> - 2012-02-02 12:25 -0500
            Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-03 14:08 +1100
              Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-03 05:04 +0000
                Re: copy on write Chris Angelico <rosuav@gmail.com> - 2012-02-03 16:28 +1100
                Re: copy on write Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-03 07:35 -0800
                Re: copy on write Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2012-02-03 10:08 +0100
                Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-03 21:47 +1100
                Re: copy on write Wolfram Hinderer <wolfram.hinderer@googlemail.com> - 2012-02-05 06:09 -0800
                Re: copy on write "OKB (not okblacke)" <brenNOSPAMbarn@NObrenSPAMbarn.net> - 2012-02-03 16:15 +0000
      Re: copy on write Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-02-02 11:42 +0100
    Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-13 08:50 -0500
      Re: copy on write Grant Edwards <invalid@invalid.invalid> - 2012-01-13 15:13 +0000
        Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-13 11:48 -0500
          Re: copy on write Neil Cerutti <neilc@norwich.edu> - 2012-01-13 16:54 +0000
            Re: copy on write Grant Edwards <invalid@invalid.invalid> - 2012-01-13 18:15 +0000
              Re: copy on write Chris Angelico <rosuav@gmail.com> - 2012-01-14 05:26 +1100
                Re: copy on write Grant Edwards <invalid@invalid.invalid> - 2012-01-13 19:30 +0000
                Re: copy on write Neil Cerutti <neilc@norwich.edu> - 2012-01-13 20:11 +0000
            Re: copy on write Evan Driscoll <edriscoll@wisc.edu> - 2012-01-13 13:24 -0600
              Re: copy on write Neil Cerutti <neilc@norwich.edu> - 2012-01-13 21:20 +0000
                Re: copy on write Evan Driscoll <edriscoll@wisc.edu> - 2012-01-13 16:48 -0600
                Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-02 05:33 -0800
                Re: copy on write Evan Driscoll <edriscoll@wisc.edu> - 2012-02-02 15:20 -0600
                Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-02 05:33 -0800
                Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-03 14:16 -0800
                Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-03 14:16 -0800
          Re: copy on write Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-01 19:51 -0800
            Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 05:31 +0000

csiph-web