inconsistency with += between different types ?

Christopher A. Craig list-python at ccraig.org
Wed Aug 7 20:53:25 CEST 2002


Bernhard Herzog <bh at intevation.de> writes:

> > You do realize that at the end of this += would only apply to lists
> > and would be exactly identical to list.append(), right? 
> 
> More like .extend actually.

I stand corrected

> > Because ints,
> > longs, floats, tuples, and in the future rationals are all immutable
> > and thus cannot return self.
> 
> So what? Immutable objects don't have to implement __iadd__ et al. at
> all and in fact ints don't have __iadd__. Python falls back to calling
> __add__ and normal assignment automatically.

While this is true, "fixing" __iadd__ as he requested and retaining
that behavior wouldn't solve the problem he is trying to address (the
differences between tuples and lists in augmented assignment).  I
presumed that when he said this he meant augmented assignment in
general rather than just __iadd__

-- 
Christopher A. Craig <list-python at ccraig.org>
"The mistakes made by Congress wouldn't be so bad if the next Congress
didn't keep trying to correct them." Cullen Hightower




More information about the Python-list mailing list