Steven D'Aprano <[EMAIL PROTECTED]> writes: > > It never occurred to me that immutable objects could implement __iadd__. > > If they can, I'm puzzled as to why.
> I'm surprised that it never occurred to you that people might > want to do something like x = 1; x += 1 in Python, But I wouldn't expect that to mean that ints implement __iadd__. I'd expect the x+=1 to just use __add__. I haven't checked the spec though. > I can respect the position of somebody who says that only methods > should be inherited -- somebody, I think it was you, suggested that there > is at least one existing OO language that doesn't allow inheritance for > attributes, but never responded to my asking what language it was. I was thinking of Flavors. You use a special function (send) to do method calls. But people generally felt that was kludgy and CLOS eliminated it. I'm not sure what happens in Smalltalk. > instance.attribute sometimes reading from the class attribute is a feature > of inheritance; instance.attribute always writing to the instance is a > feature of OOP; instance.attribute sometimes writing to the instance and > sometimes writing to the class would be, in my opinion, not just a wart > but a full-blown misfeature. But that is what you're advocating: x.y+=1 writes to the instance or the class depending on whether x.y is mutable or not. Say you have an immutable class with a mutable subclass or vice versa. You'd like to be able to replace a class instance with a subclass instance and not have the behavior change (Liskov substitution principle), etc. -- http://mail.python.org/mailman/listinfo/python-list