[Python-Dev] Re: Pre-PEP: Mutable keys in dictionaries

Eric mailing-lists@digitaleric.net
Thu, 06 Feb 2003 12:09:55 -0500


Just van Rossum wrote:

[snip]
> 
> The __temporary_immutable__ part of the protocol is needed to avoid
> unneccesary copying in those cases where the key isn't actually inserted
> into the dict, but is only used for membership testing. It would return
> a wrapper around the mutable object, defining __eq__ and __hash__. (This
> idea is stolen from the sets.py module.) If an implementer doesn't care
> about this efficiency, __temporary_immutable__ can be an alias to
> __immutable_copy__.

Can __temporary_immutable__ work on a multi-threaded system?  What is to 
prevent the (known to be mutable) key from changing underneath you during 
the lookup?  Perhaps I am misunderstanding, but it seems to me that you 
must either copy the mutable key or be able to block all writers to the key 
during the lookup.

Other than that, I very much like the idea of using mutable keys :)

-Eric