inconsistency with += between different types ?

Donn Cave donn at
Tue Aug 6 18:55:00 CEST 2002

Quoth Andreas.Leitgeb at (Andreas Leitgeb):
| Huaiyu Zhu <huaiyu at> wrote:
| > That's what it should be.  Yet it is possible for whoever writes __iadd__ to
| > define it the other way.  
| Really ?
| Inside __iadd__ I've got the "self"-parameter:
|  If I assign directly to "self", then it won't have any effect outside 
|    the method.
|  If I assign to self.whatever, I mutate the object in place.
| Is there something I've missed, or does it indeed boil down to 
|  defining or not defining __ixxx__ ?

Bear in mind that your question was about the external effect -
  obj = oldobj
  obj += val
  if obj is oldobj:
      print 'A, obj incremented in place'
      print 'D, obj is now', repr(obj)

You can control that from __iadd__, is the point.  Look at
your experiments again, how is that working out?

	Donn Cave, donn at

More information about the Python-list mailing list