inconsistency with += between different types ?

Jonathan Hogg jonathan at
Tue Aug 6 10:16:27 CEST 2002

On 5/8/2002 23:54, in article slrnaku0ge.116.huaiyu at,
"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.  I think this is exactly Donn's point: that += was
> designed in such a way that both semantics are allowed under the same
> notation.

You're always at the mercy of a module author to define sensible semantics
for operators. Unfortunately, that's life. __iadd__ has to be able to
support both models to support mutable and non-mutable objects. Which
semantics you choose is a judgement call on what the users of the type would

But you've missed the most obvious concern: if you don't define __iadd__ but
you do define __add__ then you automatically get a version of __iadd__ that
uses re-assignment, even if you're a mutable object ;-)


More information about the Python-list mailing list