Tuples and immutability

Joshua Landau joshua at landau.ws
Sun Mar 9 13:54:46 EDT 2014


On 28 February 2014 14:43, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Mar 1, 2014 at 1:41 AM, Joshua Landau <joshua at landau.ws> wrote:
>> Would it be better to add a check here, such that if this gets raised
>> to the top-level it includes a warning ("Addition was inplace;
>> variable probably mutated despite assignment failure")?
>
> That'd require figuring out whether or not the variable was actually
> mutated, and that's pretty hard to work out.

It does not. First, the "warning" is actually an attachment to the
exception so is only shown if the exception is uncaught. This should
basically never happen in working code. The warning exists only to
remove likely misunderstanding in these odd cases.

Even if "x = (1,); x[0] += 1" warned "addition was inplace; possible
mutation occurred" or whatever phrasing you wish, this would only
cause a quick check of the results.



More information about the Python-list mailing list