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 item inside tuple seemingly allows for item assignment even after throwing error
Type: behavior Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Rahul Bishain, eric.smith, rhettinger
Priority: normal Keywords:

Created on 2020-04-12 19:41 by Rahul Bishain, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg366264 - (view) Author: Rahul B (Rahul Bishain) Date: 2020-04-12 19:41
Even though item assignment throws error, the list inside tuple 'a' gets modified in place. Refer below, where the list value [8] gets added to the list value [5,6,7,7] at a[3]

>>> a
(2, 3, 4, [5, 6, 7, 7], 1)
>>> id(a[3])
140531212178376
>>> a[3]+=[8]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> a
(2, 3, 4, [5, 6, 7, 7, 8], 1)
>>> id(a[3])
140531212178376
msg366267 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-04-12 20:46
This isn't a bug. See the FAQ:
https://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-raise-an-exception-when-the-addition-works
History
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84445
2020-04-12 20:46:31eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg366267

resolution: not a bug
stage: resolved
2020-04-12 19:47:04rhettingersetnosy: + rhettinger
2020-04-12 19:41:29Rahul Bishaincreate