Could you explain this rebinding (or some other action) on "nums = nums"?

Erik python at lucidity.plus.com
Tue Dec 1 17:34:13 EST 2015


On 01/12/15 21:37, Denis McMahon wrote:
> The assignment succeeds. That's imo a bug. If it's a TypeError to try and
> assign a value to tup[1], then tup[1] should not allow the mutated list
> to be assigned.

Nothing got assigned.

That original list object remains in that slot. However, it has been 
mutated since it was originally assigned.

But I can see what you're getting at - what you're asking for is that 
the *container* object whose element is being assigned to is first 
queried as to whether it will accept a mutated element being assigned to 
it before that element is mutated.

This looks to be a fundamental issue with the augmented assignment 
mechanism.

E.



More information about the Python-list mailing list