Why are tuples immutable?

Antoon Pardon apardon at forel.vub.ac.be
Tue Dec 21 11:37:20 CET 2004


Op 2004-12-18, Bengt Richter schreef <bokr at oz.net>:
>>
>>As it turns out, python makes no difference in difficulty for making
>>either mutable or immutable objects usable as dictionary keys. The
>>only difference is that python only made its standard immutable
>>types hashable and not its standard mutable objects.
>>
> In one sense a mutable could looked upon as immutable until it is mutated,
> so why not allow its use in the same way as immutables?
> Is that basically the point of view you are trying to explain?
>
> Ok, suppose you did allow that. What kind of error symptoms would you like
> to have after a dict key is mutated and an attempt is made to look up the value
> using a mutable equal to the original key value? Presumably a KeyError exception?
> Or did you want to use a "frozen" copy of the original key, and not get a KeyError?
> Or should a new value equal to the mutated current value of the original key succeed?

Why should we expect certain error symptoms? If you have sorted mutable
objects, mutated one element in the list and then apply an algorithm
that depended on the list to be sorted; would you then expect a
particular error symptom?

> Assuming the latter, what does this imply implementation-wise?

You assume wrongly. I'm a bit sorry for that, because you obviously
spend time in this.

> Hm, just for the heck of it, does this do what you want? (all features not tested, none tested beyond what you see,
> and special methods like update and iterators will just work on the plain dict part if they work at all, unless
> you add the code ;-)

I don't expect anyting special. Python provides all that is needed. It
is just that the documentation suggests otherwise.

-- 
Antoon Pardon



More information about the Python-list mailing list