[Python-Dev] bool does not want to be subclassed? (original) (raw)

François Pinard pinard at iro.umontreal.ca
Mon Feb 16 15:15:16 EST 2004


[Martin von Löwis]

A mutable type is one whose instances have state that can change over the life of the object. [...]

Interesting presentation. The following detail is worth stressing:

equal objects should hash equal.

This should be stressed as a formal requirement for a correctly behaved hashing function. The other formal requirement being that a hash function should always compute the same value for the lifespan of an object, and that value should be a non-negative integer (not a long one?). A desirable property, but not a requirement, is that two unequal objects yield different hashes.

So, instead of explaining how we should cleverly use __hash__' to describe immutability, we might describe what hash' ought to be, and then merely notice that hashable objects could be useful to represent immutable objects (whether user objects or builtin objects).

-- François Pinard http://www.iro.umontreal.ca/~pinard



More information about the Python-Dev mailing list