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


Groups > comp.lang.python > #19779

Re: copy on write

Date 2012-02-02 19:11 +1100
From John O'Hagan <research@johnohagan.com>
Subject Re: copy on write
References (2 earlier) <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>
Newsgroups comp.lang.python
Message-ID <mailman.5348.1328170324.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, 2 Feb 2012 01:34:48 -0500
Devin Jeanpierre <jeanpierreda@gmail.com> wrote:

> On Wed, Feb 1, 2012 at 10:18 PM, John O'Hagan
> <research@johnohagan.com> wrote:
> > On Fri, 13 Jan 2012 10:40:47 -0800
> > Ethan Furman <ethan@stoneleaf.us> 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 "<stdin>", line 1, in <module>
> >> > 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


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