[Python-Dev] Add a "transformdict" to collections

R. David Murray rdmurray at bitdance.com
Thu Sep 12 17:46:11 CEST 2013

On Thu, 12 Sep 2013 08:05:44 -0700, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 09/12/2013 07:43 AM, Antoine Pitrou wrote:
> >
> > Yeah, so this is totally silly. What you're basically saying is "we
> > don't need TransformDict since people can re-implement it themselves".
> No, what I'm saying is that the "case-preserving" aspect of
> transformdict is silly.  The main point of transformdict is to enable,
> for example, 'IBM', 'Ibm', and 'ibm' to all match up as the same key.
> But why?  Because you don't trust the user data.  And if you don't
> trust the user data you have to add the correct version of the key
> yourself before you ever process that data, which means you already
> have the correct version stored somewhere.

No, in the *(original use case* (and many other use cases, such as the
identity dict) we *do* trust the user data.  It is more trustworthy than
the key forms used to look up the data inside the program.  That's the
whole point.  (Don't be distracted by Eric's particular use case.)

But even for the general case...well, let me repost here what I said on
the tracker:

In our view, this data structure is for cases where the original
key is the most important piece of information (about the keys).
The transformation in the lookup process is entirely in the service of
looking up the value paired with that original key when there is more
than one possible representation of that key.  It is the original key
that is critical when re-serializing the data or otherwise making use
of the keys for anything other than lookup.  So this is about making
the data structure succinctly model the problem domain, which is what
OO is supposed to be good at :)


More information about the Python-Dev mailing list