[New-bugs-announce] [issue13707] Clarify hash() lifetime

Terry J. Reedy report at bugs.python.org
Wed Jan 4 01:40:53 CET 2012


New submission from Terry J. Reedy <tjreedy at udel.edu>:

Current 3.2.2 docs:

id(object) Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. [model]

hash(object) Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys 

Suggestion: change "Hash values are integers. They ..." to
"This should be an integer which is constant for this object during its lifetime. Hash values ..."

Rationale: For builtin class instances, hash values are guaranteed to be constant that long, and only that long, as the default hash(ob) for object() instances is currently, for my win7, 64 bit, 3.2.2 CPython, id(ob) // 16 (the minimum object size). User class instance hashes (with custom __hash__) *should* have the same lifetime. But since Python cannot enforce that, I did not say 'guaranteed'.

User code should *not* depend on a longer lifetime, just as for id() output. It seems worth implying that, as for id(), because (based on recent pydev discussion) people seems to be prone to over-generalize the current longer-term stability of number and string hashes, which itself may disappear in future releases. (see #13703)

----------
assignee: docs at python
components: Documentation
messages: 150561
nosy: docs at python, terry.reedy
priority: normal
severity: normal
stage: needs patch
status: open
title: Clarify hash() lifetime
type: enhancement
versions: Python 2.7, Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13707>
_______________________________________


More information about the New-bugs-announce mailing list