inconsistency with += between different types ?

Huaiyu Zhu huaiyu at
Thu Aug 8 21:23:56 CEST 2002

Donn Cave <donn at> wrote:
>| Once that's done, the documentation could be as simple as:
>|   If __iadd__ is defined, x+=y changes x in place as per x.__iadd__(y).
>|   Otherwise x+=y has a semantics similar x=x+y, except that x is only
>|   evaluated once.
>| In contrast, I'd challenge anyone to explain the current += behavior in less
>| than twice that many words without misleading casual readers.
>But that isn't really the best documentation either.  I mean,
>what if we document x + y as ``whatever x.__add__(y) may do?''
>Somehow you need to define under what circumstances you would
>expect one behavior, vs. the other.  If you retreat to the
>implementation for that, then you're saying you don't know unless
>you're familiar with the implementation - does it have __iadd__
>or not?  May as well require you to know what __iadd__ does.

I don't quite follow you here.  

> As long as += has a rebinding
>effect in some cases, I think that's a legitimate implementation

That does not mean __iadd__ has to be tied up to +=.  The symbol += also
works when __iadd__ is not defined.  So the same arguemnt can work the other
way.  My other follow up gives more details.


More information about the Python-list mailing list