[Python-Dev] PEP 455: TransformDict

Victor Stinner victor.stinner at gmail.com
Sat Oct 5 23:08:34 CEST 2013


2013/10/4 Raymond Hettinger <raymond.hettinger at gmail.com <javascript:;>>:
> Please do conduct your own API tests and report back.

I don't understand why there is a need to evaluate a "new" API:
TransformDict has the same API than dict. The only differences are that the
constructor takes an extra mandatory parameter and there is a new getitem()
method. All other methods are the same: len(dict), key in dict,
dict.get(key), dict[key]=value, etc.

> This is necessary for a new class like TransformDict
> that was constructed from scratch and proposed for
> direct admission to the standard library.

The class is not "new": it is based on the API of dict, and existing
specialized implementations already used in the wild.

But I didn't compare TransformDict to existing specialized
implementations... Antoine: do you know if your API is different? Maybe in
some minor(?) details like storing the first key or last key.

> This contrasts with other tools like OrderedDict, ChainMap,
> and namedtuple which started their lives outside the standard
> library where we we able observe their fitness for real problems
> being solved by real users.

Why do you say that TransformDict has no real use case, whereas similar
containers are already used since many years in the Python standard
library? Extract of the PEP:

"Several modules in the standard library use identity lookups for object
memoization, for example pickle, json, copy, cProfile, doctest and
_threading_local."

I didn't check this whole list, but it looks like some modules can directly
use TransformDict(id), see for example the copy module.

And "case insenstive" dictionaries are also used in various projects
according to the PEP. Or do you mean that there are too few projects or
they are not popular enough?

In Python, email.Message uses a case-insensitive container preserving the
original case, except that it does also transform the value. email.Message
is used in http.client to parse HTTP headers. Twisted has its own
InsensitiveDict type for that (which does not transform the value).
http://twistedmatrix.com/documents/current/api/twisted.python.util.InsensitiveDict.html

> In short, we need to know whether the API will make sense to people,
> whether their code will be more readable with a TransformDict,
> and whether the zoo of dict variants should continue to grow.

Maybe Antoine can provide us a patch on the Python standard library to
reuse TransformDict(id) where it is possible. So we can compare the code
before/after to see if it's more readable or not.

> “… in order to get things merged you need to solve not only just your own
> problem but also realize that the world is bigger than your company and
try
> to solve things in a way where it makes sense for other people, even if
> primarily it is for your own situation.” -- Linus Torvalds
>
http://www.extremeta.com/2013/09/linus-torvalds-said-linuxcon-kernel-developer-panel/390

Existing implementations are specific (id() or str.lower()), whereas
Antoine's container is generic (transform function). Or do you mean that
it's not enough generic? It should do something on the value?

Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20131005/c907b402/attachment.html>


More information about the Python-Dev mailing list