Re: Invertible id(), or maybe hash the world, or ?

Guido.van.Rossum@cwi.nl
Mon, 11 Apr 1994 19:00:00 +0200

> BTW, if code objects aren't mutable (not sure offhand), it's probably
> just an oversight that they're not hashable (i.e., that they can't be
> used to index dicts).

The reason that code objects aren't hashable is that they contain two
lists: a list of listerals (constants) used in the code and a list of
names. I discovered this myself after already writing the code for
hashing code objects :-(.

These two components are lists instead of tuples because the
implementation has no efficient way of translating a list into a tuple
with the same elements and these data structures are built up by
appending elements at the end during compilation.

There is no deep fundamental reason why this couldn't be changed.

NB immutable objects need not be hashable: they may contain a mutable
object. E.g. (1, 2, [3, 4]) is a tuple and this immutable but not
hashable because [3, 4] is not hashable and h the hash of a tuple is a
function of the hashes of its components.

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>