Add vs in-place add of str to list

rs387 rstarkov at gmail.com
Thu Oct 2 08:43:58 EDT 2008


On Oct 2, 8:11 am, Erik Max Francis <m... at alcyone.com> wrote:
> It's because the `+=` operator is doing the equivalent of calling the
> `extend` method, which treats its argument as a generic sequence, and
> doesn't enforce type.

I see. Do you know whether this is seen as a problem with the language
design?

If so, this could be fixed by changing list.__add__ to call .extend on
the left argument if it's a list... Or, by changing __iadd__ to throw
a TypeError, whichever way around is seen as more correct/desirable.



More information about the Python-list mailing list