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


Groups > comp.lang.python > #19794

Re: copy on write

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'debug': 0.03; 'interpreter': 0.05; 'situation.': 0.05; 'omit': 0.07; 'suggesting': 0.07; 'python': 0.08; 'immutable': 0.09; 'mutable': 0.09; 'object?': 0.09; 'tuple': 0.09; 'tuple.': 0.09; '"+="': 0.16; 'assignment?': 0.16; 'both.': 0.16; 'disguise': 0.16; 'element,': 0.16; 'elsewhere,': 0.16; 'int.': 0.16; 'maybe,': 0.16; 'mysterious': 0.16; 'non-built-in': 0.16; 'obviously,': 0.16; 'omitting': 0.16; 'predict': 0.16; 'subject:copy': 0.16; 'suppose)': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; "wouldn't": 0.17; 'modified': 0.18; 'say,': 0.19; 'seems': 0.19; 'feb': 0.22; 'header:In-Reply-To:1': 0.22; 'interpreted': 0.23; "shouldn't": 0.23; 'sender:addr:gmail.com': 0.25; 'creating': 0.25; 'expect': 0.26; 'all,': 0.27; 'says': 0.27; "i'm": 0.27; 'raise': 0.28; 'lists': 0.28; '(and': 0.29; 'augmented': 0.30; 'can,': 0.30; 'gmt': 0.30; 'none,': 0.30; 'object.': 0.30; 'received:209.85.210.46': 0.30; 'received:mail- pz0-f46.google.com': 0.30; 'tuples': 0.30; 'error': 0.30; 'thu,': 0.32; 'actually': 0.32; 'objects': 0.32; 'list': 0.32; "can't": 0.32; 'it.': 0.33; 'to:addr:python-list': 0.33; 'it?': 0.33; 'object': 0.33; 'there': 0.33; 'right,': 0.34; 'assignment': 0.34; 'something': 0.35; 'uses': 0.36; 'none': 0.36; '(by': 0.36; 'element': 0.36; 'charset:us-ascii': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'could': 0.37; 'steven': 0.38; 'received:209.85': 0.38; 'think': 0.38; 'should': 0.38; 'except': 0.39; 'either': 0.39; 'sense': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'type': 0.60; 'received:203': 0.60; 'more': 0.61; 'happen': 0.61; 'john': 0.62; 'applying': 0.62; 'header:Message-Id:1': 0.62; 'fact,': 0.63; 'harder': 0.64; 'succeed': 0.73; 'with,': 0.73; 'failure': 0.74; 'place?': 0.84; 'subject:write': 0.84; 'received:home': 0.91; 'besides,': 0.93; '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=kmiqpeyqaeJMWa1Nry38O1insfIAmpjiw1oTLO5Oddo=; b=luDb1CKryWBSLy0k1a/C+DYj5gVxrbIzPOeczN/TsMPsXHNkEJFrIHVYhyei/JZQlT zfcgZO0FYsoxLbkZbBaClNFfk12U/gyhsPP/e/qpNbKDWa9PJM3BC2Q+bWY/gfcGH7Fj QIJtlXrRy1b9Kvv7SBFR3YQ/PrK5m5ppJN3d4=
Sender "John O'Hagan" <johnmohagan@gmail.com>
Date Fri, 3 Feb 2012 01:17:48 +1100
From John O'Hagan <research@johnohagan.com>
To python-list@python.org
Subject Re: copy on write
In-Reply-To <4f2a5478$0$29895$c3e8da3$5496439d@news.astraweb.com>
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>
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.5358.1328192279.27778.python-list@python.org> (permalink)
Lines 55
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328192279 news.xs4all.nl 6856 [2001:888:2000:d::a6]:45554
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19794

Show key headers only | View raw


On 02 Feb 2012 09:16:40 GMT
Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:

> On Thu, 02 Feb 2012 19:11:53 +1100, John O'Hagan wrote:
> 
> > 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.
> 
> Do you expect that x += 1 should succeed? After all, "increment and 
> decrement numbers" is practically THE use-case for the augmented 
> assignment operators.
> 
> How can you expect x += 1 to succeed without an assignment? 

I don't; obviously, for immutable objects assignment is the only possibility.

[...]
> 
> Perhaps you are thinking that Python could determine ahead of time 
> whether x[1] += y involved a list or a tuple, and not perform the
> finally assignment if x was a tuple. Well, maybe, but such an
> approach (if possible!) is fraught with danger and mysterious errors
> even harder to debug than the current situation. And besides, what
> should Python do about non-built-in types? There is no way in general
> to predict whether x[1] = something will succeed except to actually
> try it.

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.

[...]

> > 
> > 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.
> 
> How should the interpreter deal with other objects which happen to
> raise TypeError? By always ignoring it?
> 
> x = [1, None, 3]
> x[1] += 2  # apparently succeeds
> 
> Or perhaps by hard-coding tuples and only ignoring errors for tuples?
> So now you disguise one error but not others?

I'm not suggesting either of those. None can't be modified in place. But for objects which can, wouldn't omitting the final assignment prevent the TypeError in the first place?

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