Modules are hashable?!

Alex Martelli aleaxit at yahoo.com
Wed Sep 1 07:26:22 EDT 2004


Leif K-Brooks <eurleif at ecritters.biz> wrote:

> I was just playing around, and noticed that modules seem to be hashable.
> Can anyone explain that, especially given the fact that they're mutable?

Any object x is hashable if type(x) does not expose __eq__ nor __cmp__.
In that case, the meaning of x==y for that object is 'x is y', that is,
id(x)==id(y), so having hash(x) return id(x) is perfectly functional.
Mutation is not a problem if it doesn't affect equality comparisons.


Alex



More information about the Python-list mailing list