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: Strange behavior on the tuple that includes list
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, furkanonder
Priority: normal Keywords:

Created on 2022-03-29 20:26 by furkanonder, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg416291 - (view) Author: Furkan Onder (furkanonder) * Date: 2022-03-29 20:26
I am creating the tuple that includes a list and than I am trying to add new value to this list. Interpreter throw the error, but list is changing. I think it doesn't make sense. I think if we throw the type error, list shouldn't be change.

>>> tup = ('hi', 'test', ['a','b'])
>>> tup[2] += 'c'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> tup
('hi', 'test', ['a', 'b', 'c'])
>>>
msg416292 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-03-29 20:29
This is an FAQ: https://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-raise-an-exception-when-the-addition-works
msg416293 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-03-29 20:29
There's also this StackOverflow question about it: https://stackoverflow.com/questions/38344244/tuples-operator-throws-exception-but-succeeds
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91311
2022-03-29 20:29:51eric.smithsetstatus: open -> closed
type: behavior
messages: + msg416293

resolution: not a bug
stage: resolved
2022-03-29 20:29:11eric.smithsetnosy: + eric.smith
messages: + msg416292
2022-03-29 20:26:04furkanondercreate