inconsistency with += between different types ?
Christopher A. Craig
list-python at ccraig.org
Wed Aug 7 18:42:14 CEST 2002
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
> 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? Because ints,
longs, floats, tuples, and in the future rationals are all immutable
and thus cannot return self.
As an example:
So your proposed change would make augmented assignment fail on all
numeric types. That seems a rather bad choice to me.
Christopher A. Craig <list-python at ccraig.org>
"In the beginning the Universe was created. This has made a lot of people
very angry and been widely regarded as a bad move." Douglas Adams
More information about the Python-list