This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: list + tuple inconsistency
Type: Stage:
Components: Versions: Python 3.2
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: gruszczy, rhettinger
Priority: normal Keywords:

Created on 2011-06-11 22:02 by gruszczy, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg138185 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-06-11 22:02
You can do this:
>>> [1] + (1,)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "tuple") to list

But you can do this:

>>> result = [1]
>>> result += (1,)
>>> result
[1, 1]


Is it the expected behaviour, that += does implicit coercion?
msg138186 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-06-11 22:03
Obviously first sentence should be "You can't do this:".
msg138188 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-06-11 22:49
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 like list.extend).
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56527
2011-06-11 22:49:21rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg138188

resolution: not a bug
2011-06-11 22:03:24gruszczysetmessages: + msg138186
2011-06-11 22:02:51gruszczycreate