inconsistency with += between different types ?
huaiyu at gauss.almadan.ibm.com
Tue Aug 6 19:00:56 CEST 2002
Jonathan Hogg <jonathan at onegoodidea.com> wrote:
>On 5/8/2002 23:54, in article slrnaku0ge.116.huaiyu at gauss.almadan.ibm.com,
>"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. I think this is exactly Donn's point: that += was
>> designed in such a way that both semantics are allowed under the same
>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
I'm not convinced of the "has to" part. It's a different semantics. If it
has to be supported, it could be using a different symbol.
And I'm not convinced you have to be at the mercy of module author: If the
implementation were to always return self implicitly, you always get the
>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 ;-)
Didn't I say "the definition (or lack of) __iadd__"? I'm glad we now agree
that with the current implementation, this is the only thing that matters.
Mutability does not play a role here.
More information about the Python-list