[Python-Dev] Re: accumulator display syntax

Raymond Hettinger python at rcn.com
Sun Oct 26 12:34:55 EST 2003


> > If this were the approach taken, it seems to me that there could not
be
> any
> > semantic change or side-effects for types that have compatible
meaning
> for
> > + and += (i.e. += is an in-place version of +).
> >
> > Maybe I'm missing something here?
> 
> Only the fact that "there's nothing that guarantees" this, as Guido
says.
> alist = alist + x only succeds if x is also a list, while alist += x
> succeeds
> also for tuples and other sequences, for example.
> 
> Personally, I don't think this would be a problem, but it's not my
> decision.


In the context of sum(), I think it would be nice to allow iterables to
be added together:   sum(['abc', range(3), ('do', 're', 'me')], [])

This fits in well with the current thinking that the prohibition of
adding sequences of unlike types be imposed only on operators and not on
functions or methods.  For instance, in sets.py, a|b requires both a and
b to be Sets; however, a.union(b) allows b to be any iterable.  The
matches the distinction between list.__iadd__() and list.extend() where
the former requires a list argument and the latter does not.


Raymond Hettinger




More information about the Python-Dev mailing list