Can anyone familiar with Python\'s internals (CPython, or other implementations) explain why list addition is required to be homogenous:
In [1]: x = [1]
In
These bug reports suggest that this design quirk was a mistake.
Issue12318:
Yes, this is the expected behavior and yes, it is inconsistent.
It's been that way for a long while and Guido said he wouldn't do it again (it's in his list of regrets). However, we're not going to break code by changing it (
list.__iadd__working likelist.extend).
Issue575536:
The intent was that
list.__iadd__correspond exactly tolist.extend(). There's no need to hypergeneralizelist.__add__()too: it's a feature that people who don't want to get surprised by Martin-like examples can avoid them by using plain+for lists.
(Of course, there are those of us who find this behaviour quite surprising, including the developer who opened that bug report).
(Thanks to @Mouad for finding these).