inconsistency with += between different types ?

Donn Cave donn at u.washington.edu
Tue Aug 6 18:55:00 CEST 2002


Quoth Andreas.Leitgeb at siemens.at (Andreas Leitgeb):
| Huaiyu Zhu <huaiyu at gauss.almadan.ibm.com> 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'
  else:
      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 u.washington.edu



More information about the Python-list mailing list