[issue40911] Unexpected behaviour for += assignment to list inside tuple

2020-06-08 Thread Adam Cmiel
Adam Cmiel added the comment: Got it, I didn't realize that the last step of augmented assignment is (in this case) assigning the result of __iadd__ back to the tuple. Thanks for the explanations! -- ___ Python tracker

[issue40911] Unexpected behaviour for += assignment to list inside tuple

2020-06-08 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: Multiple steps happens at once here, first the list is extended, then the result is written back to the tuple, at which point it raises TypeError because you can't write to a tuple. When TypeError is raised, the list has already be extended. The code is

[issue40911] Unexpected behaviour for += assignment to list inside tuple

2020-06-08 Thread Steven D'Aprano
Steven D'Aprano 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

[issue40911] Unexpected behaviour for += assignment to list inside tuple

2020-06-08 Thread Adam Cmiel
New submission from Adam Cmiel : Python version: Python 3.8.3 (default, May 15 2020, 00:00:00) [GCC 10.1.1 20200507 (Red Hat 10.1.1-1)] on linux Description: When assigning to a tuple index using +=, if the element at that index is a list, the list is extended and a TypeError is raised. a