Steven D'Aprano <steve+pyt...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue40911> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com