[Python-Dev] Add a frozendict builtin type

Raymond Hettinger raymond.hettinger at gmail.com
Wed Feb 29 20:17:05 CET 2012


On Feb 27, 2012, at 10:53 AM, Victor Stinner wrote:

> A frozendict type is a common request from users and there are various
> implementations. 

ISTM, this request is never from someone who has a use case.
Instead, it almost always comes from "completers", people
who see that we have a frozenset type and think the core devs
missed the ObviousThingToDo(tm).  Frozendicts are trivial to 
implement, so that is why there are various implementations
(i.e. the implementations are more fun to write than they are to use).

The frozenset type covers a niche case that is nice-to-have but
*rarely* used.  Many experienced Python users simply forget
that we have a frozenset type.  We don't get bug reports or
feature requests about the type.  When I do Python consulting
work, I never see it in a client's codebase.  It does occasionally
get discussed in questions on StackOverflow but rarely gets
offered as an answer (typically on variants of the "how do you
make a set-of-sets" question).  If Google's codesearch were still
alive, we could add another datapoint showing how infrequently
this type is used.  

I wrote the C implementation for frozensets and the tests that
demonstrate their use in problems involving sets-of-sets, yet
I have *needed* the frozenset once in my career (for a NFA/DFA
conversion algorithm).

From this experience, I conclude that adding a frozendict type
would be a total waste (except that it would inspire more people
to request frozen variante of other containers).


Raymond


P.S.  The one advantage I can see for frozensets and frozendicts
is that we have an opportunity to optimize them once they are built
(optimizing insertion order to minimize collisions, increasing or
decreasing density, eliminating dummy entries, etc).  That being
said, the same could be accomplished for regular sets and dicts
by the addition of an optimize() method.   I'm not really enamoured
of that idea though because it breaks the abstraction and because
people don't seem to need it (i.e. it has never been requested).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120229/e051c9b0/attachment.html>


More information about the Python-Dev mailing list