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>