
On 02/13/2015 06:57 PM, Andrew Barnert wrote:
On Feb 13, 2015, at 18:46, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
Andrew Barnert wrote:
I think it's reasonable for a target to be able to assume that it will get a setattr or setitem when one of its subobjects is assigned to. You might need to throw out cached computed properties, ...
That's what I was thinking. But I'm not sure it would be a good design,
Now I'm confused.
The current design of Python guarantees that an object always gets a setattr or setitem when one of its elements is assigned to. That's an important property, for the reasons I suggested above. So any change would have to preserve that property. And skipping assignment when __iadd__ returns self would not preserve that property. So it's not just backward-incompatible, it's bad.
--> some_var = ([1], 'abc') --> tmp = some_var[0] --> tmp += [2, 3] --> some_var ([1, 2, 3], 'abc') In that example, 'some_var' is modified without its __setitem__ ever being called. -- ~Ethan~