Re: Trying to understand += better

2009-11-30 Thread Terry Reedy
Roy Smith wrote: In article <4b0a01a...@dnews.tpgi.com.au>, Lie Ryan wrote: The semantic of the in-place operator is something like: x += y becomes x = x.__iadd__(y) Except that the expression x is evaluated just once instead of twice. thus foo.bar += baz becomes foo.bar = foo.bar.__iadd_

Trying to understand += better

2009-11-30 Thread Roy Smith
If I've got an object foo, and I execute: foo.bar += baz exactly what happens if foo does not have a 'bar' attribute? It's pretty clear that foo.__getattr__('bar') gets called first, but it's a little murky after that. Assume for the moment that foo.__getattr__ ('bar') returns an object x. I t

Re: Trying to understand += better

2009-11-30 Thread Steve Howell
On Nov 22, 8:38 pm, Roy Smith wrote: > In article <4b0a01a...@dnews.tpgi.com.au>, Lie Ryan > wrote: > > > The semantic of the in-place operator is something like: > > x += y > > becomes > > x = x.__iadd__(y) > > > thus > > foo.bar += baz > > becomes > > foo.bar = foo.bar.__iadd__(baz) > > > So th

Re: Trying to understand += better

2009-11-30 Thread n00m
> The first statement is creating a whole new list; Yes but *imo* not quite exactly so. We can't think of 2 lists as of absolutely independent things. ... x = [[0]] ... id(x) 19330632 ... id(x[0]) 19316608 ... z = x + [3] ... id(z) 19330312 ... id(z[0]) 19316608 ... ... z[0] is x[0] # ? True ...

Re: Trying to understand += better

2009-11-30 Thread Roy Smith
In article <4b0a01a...@dnews.tpgi.com.au>, Lie Ryan wrote: > The semantic of the in-place operator is something like: > x += y > becomes > x = x.__iadd__(y) > > thus > foo.bar += baz > becomes > foo.bar = foo.bar.__iadd__(baz) > > So the call sequence is, > foo.__getattr__('bar') ==> x > x.__i

Re: Trying to understand += better

2009-11-22 Thread Lie Ryan
Roy Smith wrote: In article <4b0a01a...@dnews.tpgi.com.au>, Lie Ryan wrote: The semantic of the in-place operator is something like: x += y becomes x = x.__iadd__(y) thus foo.bar += baz becomes foo.bar = foo.bar.__iadd__(baz) So the call sequence is, foo.__getattr__('bar') ==> x x.__iadd__(

Re: Trying to understand += better

2009-11-22 Thread Steve Howell
On Nov 22, 9:11 pm, n00m wrote: > > The first statement is creating a whole new list; > > Yes but *imo* not quite exactly so. > We can't think of 2 lists as of absolutely independent > things. > [...] You are correct that two lists can both have the same mutable object as items, and if you mutate

Re: Trying to understand += better

2009-11-22 Thread Steve Howell
On Nov 22, 7:28 pm, Lie Ryan wrote: > Roy Smith wrote: > > If I've got an object foo, and I execute: > > > foo.bar += baz > > > exactly what happens if foo does not have a 'bar' attribute?  It's > > pretty clear that foo.__getattr__('bar') gets called first, but it's a > > little murky after that.

Re: Trying to understand += better

2009-11-22 Thread Lie Ryan
Roy Smith wrote: If I've got an object foo, and I execute: foo.bar += baz exactly what happens if foo does not have a 'bar' attribute? It's pretty clear that foo.__getattr__('bar') gets called first, but it's a little murky after that. Assume for the moment that foo.__getattr__ ('bar') return