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


Groups > comp.lang.python > #67225

Re: Tuples and immutability

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joshua.landau.ws@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'assignment': 0.07; 'cc:addr:python-list': 0.11; '20]': 0.16; 'assigns': 0.16; 'in-place': 0.16; 'mutated': 0.16; 'ok...': 0.16; 'top-level': 0.16; 'tuple': 0.16; 'typeerror:': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'variable': 0.18; 'things.': 0.19; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'first,': 0.26; 'this:': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'gives': 0.31; '"",': 0.31; '>>>>': 0.31; 'asks': 0.31; 'raised': 0.31; 'file': 0.32; 'probably': 0.32; '(most': 0.33; 'fri,': 0.33; 'common': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'two': 0.37; 'whatever': 0.38; 'list,': 0.38; 'recent': 0.39; 'does': 0.39; 'then,': 0.60; 'back': 0.62; 'such': 0.63; '30,': 0.65; 'to:addr:gmail.com': 0.65; 'confusion.': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=InelPMoCr++L5Q3Dp5GibF4277SyZgCPFDexMr8KejE=; b=G6GoLRRH1uk2kRjc2VxtlyR10dHipQdbsd0oRWnYyHHojQzM3cnyg5Oe4hByr2ld1z DUdsRKpVFyrYrDmzTPofvJeuzhFjGyXUlQX9HQ/MVhlYYLXX9C6bTHnZPcCf6Cg4fKu8 oL2CGyUDmhkX8s3H35KhgosO2TvWObwc9kLpKZR+n5uRDTy4/H0XUB/KJIso70o1vgZT 9X+BPD1ZTojBs1BV3yxToqBoOp/5cnX0CZ8uAOq7YnjCMk11sscFuNJy7L1Baz8CaPZv 5f69338SUhr5Z57r4/uN/+DZnuSsvRvLumYrx5ysqERjx8ZQaR2cc2egt2qsqt6x3d4/ L7cg==
X-Received by 10.112.125.225 with SMTP id mt1mr10948300lbb.35.1393598520136; Fri, 28 Feb 2014 06:42:00 -0800 (PST)
MIME-Version 1.0
Sender joshua.landau.ws@gmail.com
In-Reply-To <CAPTjJmomgZSFj7TanBn8_qXP4ULhCm85abJ5=2PcikXJkrH6GQ@mail.gmail.com>
References <lennh4$kpm$1@cabale.usenet-fr.net> <CAPTjJmomgZSFj7TanBn8_qXP4ULhCm85abJ5=2PcikXJkrH6GQ@mail.gmail.com>
From Joshua Landau <joshua@landau.ws>
Date Fri, 28 Feb 2014 14:41:20 +0000
X-Google-Sender-Auth SpFnMmaBHrHGOiyJMSEc-l9Hu5c
Subject Re: Tuples and immutability
To Chris Angelico <rosuav@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.7471.1393598528.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1393598528 news.xs4all.nl 2891 [2001:888:2000:d::a6]:58191
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:67225

Show key headers only | View raw


On 27 February 2014 16:14, Chris Angelico <rosuav@gmail.com> wrote:
> On Fri, Feb 28, 2014 at 3:01 AM, Eric Jacoboni <eric.jacoboni@gmail.com> wrote:
>>
>>>>> a_tuple = ("spam", [10, 30], "eggs")
>>>>> a_tuple[1] += [20]
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> TypeError: 'tuple' object does not support item assignment
>>
>> Ok... I accept this message as += is a reassignment of a_tuple[1] and a
>> tuple is immutable...
>>
>> But, then, why a_tuple is still modified?
>
> This is a common confusion.
>
> The += operator does two things. First, it asks the target to please
> do an in-place addition of the other operand. Then, it takes whatever
> result the target gives back, and assigns it back into the target. So
> with a list, it goes like this:
>
>>>> foo = [10, 30]
>>>> foo.__iadd__([20])
> [10, 30, 20]
>>>> foo = _

Would it be better to add a check here, such that if this gets raised
to the top-level it includes a warning ("Addition was inplace;
variable probably mutated despite assignment failure")?

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


Thread

Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-02-27 17:01 +0100
  Re: Tuples and immutability Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-02-27 10:13 -0600
    Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-02-27 17:27 +0100
      Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-02-28 03:33 +1100
      Re: Tuples and immutability Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-02-27 10:47 -0600
      Re: Tuples and immutability Nick Timkovich <prometheus235@gmail.com> - 2014-02-27 15:47 -0600
      Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-02-28 08:52 +1100
      Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-27 15:18 -0700
      Re: Tuples and immutability Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-03-01 18:55 +0000
  Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-02-28 03:14 +1100
  Re: Tuples and immutability Marko Rauhamaa <marko@pacujo.net> - 2014-02-27 18:19 +0200
    Re: Tuples and immutability John O'Hagan <research@johnohagan.com> - 2014-02-28 16:17 +1100
      Re: Tuples and immutability Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 09:54 +0200
  Re: Tuples and immutability Joshua Landau <joshua@landau.ws> - 2014-02-28 14:41 +0000
  Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-03-01 01:43 +1100
  Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 16:22 -0800
    Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-03-01 02:27 +0100
      Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 20:45 -0800
        Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-28 22:34 -0700
          Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 21:50 -0800
            Re: Tuples and immutability Ned Batchelder <ned@nedbatchelder.com> - 2014-03-01 12:56 -0500
      Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-28 22:26 -0700
    Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-03-01 12:39 +1100
    Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-28 22:16 -0700
      Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 22:16 -0800
        Re: Tuples and immutability Chris Angelico <rosuav@gmail.com> - 2014-03-01 17:29 +1100
        Re: Tuples and immutability Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 14:54 +0000
          Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 13:01 -0800
      Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 22:25 -0800
        Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-01 12:45 -0700
      Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 13:21 -0800
        Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-03-02 03:04 +0100
          Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 18:28 -0800
          Re: Tuples and immutability Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-02 05:32 -0700
            Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-03-02 14:38 +0100
              Re: Tuples and immutability Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-02 14:05 +0000
                Re: Tuples and immutability Eric Jacoboni <eric.jacoboni@gmail.com> - 2014-03-02 15:17 +0100
                Re: Tuples and immutability "albert visser" <albert.visser@gmail.com> - 2014-03-02 15:37 +0100
        Re: Tuples and immutability "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 18:15 -0800

csiph-web