[docs] [issue13707] Clarify hash() constancy period

Marc-Andre Lemburg report at bugs.python.org
Wed Jan 4 10:13:56 CET 2012

Marc-Andre Lemburg <mal at egenix.com> added the comment:

Terry J. Reedy wrote:
> Terry J. Reedy <tjreedy at udel.edu> added the comment:
> Martin, I do not understand. The default hash is based on id (as is default equality comparison), not value. Are you OK with hash values changing if the 'value' changes? My understanding is that changing hash values for objects in sets and dicts is bad, which is why mutable builtins with value-based equality do not have hash values.

Hash values are based on the object values, not their id(). See the
various type implementations as reference. The id() is only used
as hash for objects which don't have a "value" (and thus cannot be

Given that we have the invariant "a==b => hash(a)==hash(b)" in Python,
it immediately follows that hash values for objects with comparison
method cannot have a lifetime - at least not within the same process
and, depending how you look at it, also not in multi-process

nosy: +lemburg

Python tracker <report at bugs.python.org>

More information about the docs mailing list