[Python-Dev] Pre-PEP: Mutable keys in dictionaries
Neal Norwitz
neal@metaslash.com
Thu, 06 Feb 2003 15:48:35 -0500
On Thu, Feb 06, 2003 at 08:42:59PM +0100, Just van Rossum wrote:
>
> [GvR]
> > Could you do this as a subclass of dict? A subclass in Python would
> > be inefficient, but might still be good enough for your second use
> > case (the ObjC bridge). If not, a subclass in Python might be
> > feasible -- it would be a little bit more work than integrating it
> > into dictobject.c, but you have a lot less convincing to do, and you
> > can even get it to work with Python 2.2.
>
> But it doesn't solve our problem. We have no control over what
> dictionaries are used, either by our users directly or by the Python
> library they use. We _do_ have control over the keys that are causing
> troubles: our main problem is that we cannot rely on NSString instances
> to be immutable, yet we need the ability to use them as keys in
> (regular) dicts, just as if they were Python strings.
Couldn't you add an as_key() method to NSString? Then dict
access would always be like:
dict[nsstring.as_key()]
Neal