Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99816
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Could you explain this rebinding (or some other action) on "nums = nums"? |
| Date | Tue, 1 Dec 2015 14:44:38 -0600 |
| Lines | 39 |
| Message-ID | <mailman.83.1449002726.14615.python-list@python.org> (permalink) |
| References | <94c2e42e-1e5f-40cf-9259-26035e277bf3@googlegroups.com> <mailman.37.1435191416.3674.python-list@python.org> <b48d4b38-a28a-4408-8271-f79e850f453f@googlegroups.com> <mailman.51.1448940760.14615.python-list@python.org> <n3l050$l7a$4@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de 3keh/t32kJqqjVzO55xZ7QgeHvXjINxOgSBUR7zi6r0A== |
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'tries': 0.05; 'assignment': 0.07; '*is*': 0.09; 'called.': 0.09; 'typeerror:': 0.09; 'python': 0.10; 'result.': 0.15; '2.7.3': 0.16; '3],': 0.16; 'attempted.': 0.16; 'bug:': 0.16; 'mutated': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Could': 0.16; 'tup': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; 'refers': 0.18; '2015': 0.20; '"",': 0.22; 'trying': 0.22; 'dec': 0.23; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'subject:other': 0.29; 'subject:some': 0.29; 'skip:[ 10': 0.31; 'subject:) ': 0.32; 'traceback': 0.33; 'tue,': 0.34; 'file': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'expected': 0.35; 'item': 0.35; 'but': 0.36; 'list,': 0.36; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:209.85.213': 0.37; 'itself': 0.38; 'no,': 0.38; 'received:209': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'more': 0.63; 'of:': 0.66; 'denis': 0.84; 'to:name:python': 0.84; 'subject:this': 0.85; 'subject:you': 0.85 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=ofA0O9YgQfoMnPM7ZdH0roMLFGPLCUjEIeDCYspWDgk=; b=kaVL5eqDSFEcdEHKoR5DI7F+uKoup46QUtclu3wREsZGbd3yOspq9RiefYzDCc0mUe xM0kh3b6cc5PZlEzP4BbTTo/qU6UcsAzPc0z1syg5BoWJq0cZf2NK+XTSCVG1We7nvtB Bb5WBEhHvgla0Nl3noX3BESgSy82P1n0hlAxO549/Vk0CERf7mwewo2TmBBV48dbSJct EvgMkpzfSqu0eR5ZsFkxluQoh35mPiqRqXBq1A+mV23+bB6t4VWI/KQdAqE0NvL6AdDL pbh9lfPwYnXb/2i2AgmmtXaiYbVkNEwj4VpSf9KrcYKHXz5YrAAwzauLPZv4+OumZ6ig 5Y2A== |
| X-Received | by 10.50.73.130 with SMTP id l2mr68509igv.93.1449002717904; Tue, 01 Dec 2015 12:45:17 -0800 (PST) |
| In-Reply-To | <n3l050$l7a$4@dont-email.me> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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> |
| Xref | csiph.com comp.lang.python:99816 |
Show key headers only | View raw
On Tue, Dec 1, 2015 at 2:32 PM, Denis McMahon <denismfmcmahon@gmail.com> wrote: > On Tue, 01 Dec 2015 03:32:31 +0000, MRAB wrote: > >> In the case of: >> >> tup[1] += [6, 7] >> >> what it's trying to do is: >> >> tup[1] = tup[1].__iadd__([6, 7]) >> >> tup[1] refers to a list, and the __iadd__ method _does_ mutate it, but >> then Python tries to put the result that the method returns into tup[1]. >> That fails because tup itself is a tuple, which is immutable. > > I think I might have found a bug: > > $ python > Python 2.7.3 (default, Jun 22 2015, 19:33:41) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> tup = [1,2,3],[4,5,6] >>>> tup > ([1, 2, 3], [4, 5, 6]) >>>> tup[1] > [4, 5, 6] >>>> tup[1] += [7,8,9] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: 'tuple' object does not support item assignment >>>> tup[1] > [4, 5, 6, 7, 8, 9] >>>> tup > ([1, 2, 3], [4, 5, 6, 7, 8, 9]) >>>> quit() No, that's the expected result. As MRAB wrote, the list *is* mutated when its __iadd__ method is called. The TypeError happens afterward when the assignment is attempted.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Could you explain this rebinding (or some other action) on "nums = nums"? fl <rxjwg98@gmail.com> - 2015-11-30 18:14 -0800
Re: Could you explain this rebinding (or some other action) on "nums = nums"? MRAB <python@mrabarnett.plus.com> - 2015-12-01 03:32 +0000
Re: Could you explain this rebinding (or some other action) on "nums = nums"? Denis McMahon <denismfmcmahon@gmail.com> - 2015-12-01 20:32 +0000
Re: Could you explain this rebinding (or some other action) on "nums = nums"? Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-01 14:44 -0600
Re: Could you explain this rebinding (or some other action) on "nums = nums"? Denis McMahon <denismfmcmahon@gmail.com> - 2015-12-01 21:37 +0000
Re: Could you explain this rebinding (or some other action) on "nums = nums"? Erik <python@lucidity.plus.com> - 2015-12-01 22:34 +0000
Re: Could you explain this rebinding (or some other action) on "nums = nums"? Erik <python@lucidity.plus.com> - 2015-12-01 22:44 +0000
Re: Could you explain this rebinding (or some other action) on "nums = nums"? Terry Reedy <tjreedy@udel.edu> - 2015-12-01 16:18 -0500
Re: Could you explain this rebinding (or some other action) on "nums = nums"? Denis McMahon <denismfmcmahon@gmail.com> - 2015-12-01 21:36 +0000
Re: Could you explain this rebinding (or some other action) on "nums = nums"? Terry Reedy <tjreedy@udel.edu> - 2015-12-01 17:37 -0500
csiph-web