3 ms·
The += on tuple elements thing kind of looks like a bug in CPython.
by ngoldbaum 11y ago
The += on tuple elements thing kind of looks like a bug in CPython.
- bpicolo 11y agoAgreed. tup[0] = tup[0] + [1] fails as expected.
- maxerickson 11y agoThe semantics of augmented assignment are (slightly) different than normal assignment: https://docs.python.org/3.4/reference/simple_stmts.html#grammar-token-augmented_assignment_stmt https://docs.python.org/3.4/reference/simple_stmts.html#gram...
- aldanor 11y agoIt's quite obvious where it comes from though, it first calls __iadd__ on the list and that succeeds, and then it calls __setitem__ on the tuple which fails; however, the first operation already mutated the list. This has nothing to do with tuples, I think, as one can constructs many other examples just like this one.
- ngoldbaum 11y agoI stand corrected. My initial comment was just a gut reaction to the weirdness of an operation on builtins raising an error but still having side-effects.