Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Denis McMahon
On Tue, 01 Dec 2015 16:18:49 -0500, Terry Reedy wrote: > On 12/1/2015 3:32 PM, Denis McMahon wrote: >> On Tue, 01 Dec 2015 03:32:31 +, MRAB wrote: >> >>> In the case of: >>> >>> tup[1] += [6, 7] >>> >>> what it's trying to do is: >>> >>> tup[1] = tup[1].__iadd__([6, 7]) >>> >>>

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Terry Reedy
On 12/1/2015 3:32 PM, Denis McMahon wrote: On Tue, 01 Dec 2015 03:32:31 +, 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

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Erik
On 01/12/15 21:37, Denis McMahon wrote: The assignment succeeds. That's imo a bug. If it's a TypeError to try and assign a value to tup[1], then tup[1] should not allow the mutated list to be assigned. Nothing got assigned. That original list object remains in that slot. However, it has been

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Denis McMahon
On Tue, 01 Dec 2015 14:44:38 -0600, Ian Kelly wrote: > On Tue, Dec 1, 2015 at 2:32 PM, Denis McMahon > wrote: >> On Tue, 01 Dec 2015 03:32:31 +, MRAB wrote: >> >>> In the case of: >>> >>> tup[1] += [6, 7] >>> >>> what it's trying to do is: >>> >>> tup[1] =

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Ian Kelly
On Tue, Dec 1, 2015 at 2:32 PM, Denis McMahon wrote: > On Tue, 01 Dec 2015 03:32:31 +, 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

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Denis McMahon
On Tue, 01 Dec 2015 03:32:31 +, 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

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Erik
Apologies for self-replying, On 01/12/15 22:34, Erik wrote: what you're asking for is that the *container* object whose element is being assigned to is first queried as to whether it will accept a mutated element being assigned to it before that element is mutated. What I said above is

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-12-01 Thread Terry Reedy
On 12/1/2015 4:36 PM, Denis McMahon wrote: On Tue, 01 Dec 2015 16:18:49 -0500, Terry Reedy wrote: On 12/1/2015 3:32 PM, Denis McMahon wrote: On Tue, 01 Dec 2015 03:32:31 +, MRAB wrote: In the case of: tup[1] += [6, 7] what it's trying to do is: tup[1] =

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-11-30 Thread fl
On Wednesday, June 24, 2015 at 8:17:08 PM UTC-4, Chris Angelico wrote: > On Thu, Jun 25, 2015 at 9:52 AM, fl wrote: > > The reason is that list implements __iadd__ like this (except in C, not > > Python): > > > > class List: > > def __iadd__(self, other): > > self.extend(other) > >

Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-11-30 Thread MRAB
On 2015-12-01 02:14, fl wrote: On Wednesday, June 24, 2015 at 8:17:08 PM UTC-4, Chris Angelico wrote: On Thu, Jun 25, 2015 at 9:52 AM, fl wrote: > The reason is that list implements __iadd__ like this (except in C, not Python): > > class List: > def __iadd__(self, other): >

Could you explain this rebinding (or some other action) on nums = nums?

2015-06-24 Thread fl
Hi, I read a blog written by Ned and find it is very interesting, but I am still unclear it in some parts. In the following example, I am almost lost at the last line: nums = num Could anyone explain it in a more detail to me? Thanks, ... The reason is that list

Re: Could you explain this rebinding (or some other action) on nums = nums?

2015-06-24 Thread Chris Angelico
On Thu, Jun 25, 2015 at 9:52 AM, fl rxjw...@gmail.com wrote: The reason is that list implements __iadd__ like this (except in C, not Python): class List: def __iadd__(self, other): self.extend(other) return self When you execute nums += more, you're getting the same