inconsistency with += between different types ?
bh at intevation.de
Wed Aug 7 19:31:54 CEST 2002
list-python at ccraig.org (Christopher A. Craig) writes:
> Andreas.Leitgeb at siemens.at (Andreas Leitgeb) writes:
> > This of course explains, why it causes that much trouble.
> > A possible path to change this situation might be as follows:
> > (Although I feel too new at Python to actually propose a change :-)
> > Automatically treat a None returnvalue from an __ixxx__-method as self
> > Issue a Warning, if __ixxx__ returns anything else than self or None
> > Ignore the return-value altogether.
> > Each of these steps might have to wait for a major-version-step in
> > Python.
> > This would make sure that clean implementations would stay ok, while
> > those implementations, that obfuscate the design of <op>= will hopefully
> > phase out.
> 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.
> 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.
Intevation GmbH http://intevation.de/
More information about the Python-list