[Python-Dev] dict and required hashing

Armin Rigo arigo at tunes.org
Sat Apr 19 10:43:44 CEST 2014


Hi Jim,

On 18 April 2014 23:46, Jim J. Jewett <jimjjewett at gmail.com> wrote:
> (2)  Is "the item will be hashed at least once" a language guarantee?

I think that a reasonable implementation needs to hash at least once
all keys that are added to the dictionary.  Otherwise we end up, as
you said, with a dictionary that contains non-hashable keys: this
crashes when it grows and tries to convert from a list storage to a
hash table.  This is against the expectations and probably against the
language spec...

It's a bit unclear to me if the language spec requires "if [ ] in
mydict:" to raise TypeError, as the key doesn't get added to the dict
in this case.  Similarly for "[ ] in { }" where the dictionary is
empty anyway.  I would say yes, erring on the side of caution...


A bientôt,

Armin.


More information about the Python-Dev mailing list