[issue40911] Unexpected behaviour for += assignment to list inside tuple
Steven D'Aprano
report at bugs.python.org
Mon Jun 8 11:20:27 EDT 2020
Steven D'Aprano <steve+python at pearwood.info> added the comment:
Alas, this gotcha is the consequence of the way `+=` is defined in Python. Although the behaviour is surprising, there's nothing to fix because everything is working as expected:
* addition to a list will extend the list, as expected;
* trying to assign into a tuple will fail, as expected.
It's just the combination that is surprising.
There's even a FAQ for it:
https://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-raise-an-exception-when-the-addition-works
----------
nosy: +steven.daprano
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40911>
_______________________________________
More information about the Python-bugs-list
mailing list