This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: hashable documentation error: shouldn't mention id
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Giacomo.Alzetta, docs@python, python-dev, r.david.murray
Priority: normal Keywords:

Created on 2014-06-16 18:36 by Giacomo.Alzetta, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg220746 - (view) Author: Giacomo Alzetta (Giacomo.Alzetta) Date: 2014-06-16 18:36
The documentation for hashable in the glossary ( is incorrect:

they all compare unequal (except with themselves), **and their hash value is their id().**

It is *not* true that their hash is their id (see relevant SO question:

Also the documentation for __hash__ ( doesn't even mention id().
msg220749 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-16 19:02
The statement is poorly worded.  The id() is the *input* to the hash function used to compute the default __hash__.  This is a CPython implementation detail, though, so perhaps all mention of it should indeed be dropped.
msg220750 - (view) Author: Giacomo Alzetta (Giacomo.Alzetta) Date: 2014-06-16 19:24
"their hash value is their id()" seems quite clearly stating that:

>>> class A: pass
>>> a = A()
>>> hash(a) == id(a)

should be true, but:

>>> hash(a) == id(a)

(both in python2 and in python3)

The python 2 documentation for the __hash__ special method *does* state that the default implementation returns a value "derived" by id().
I believe there is an inconsistency. In the python2 glossary it should say:

"their hash value is derived from their id()"

While in python3 it shouldn't mention id() at all, since the documentation for __hash__ doesn't mention it at all.
msg220753 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-16 20:26
Yes, I should have been clearer.  By "poorly worded" I meant "id is involved, but the sentence does not correctly describe *how* id is involved".  That is, the sentence is wrong as written.

The implementation is the same in both Python2 and Python3, though the source code organization and how it becomes the default hash is a bit different.
msg228700 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-06 14:48
New changeset bfaf434a6f10 by Georg Brandl in branch '3.4':
Closes #21782: the default hash(x) is not exactly id(x) but derived from it.
Date User Action Args
2022-04-11 14:58:05adminsetgithub: 65981
2014-10-06 14:48:50python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg228700

resolution: fixed
stage: resolved
2014-06-16 20:26:21r.david.murraysetmessages: + msg220753
2014-06-16 19:24:48Giacomo.Alzettasetmessages: + msg220750
2014-06-16 19:02:06r.david.murraysetnosy: + r.david.murray
messages: + msg220749
2014-06-16 18:36:54Giacomo.Alzettacreate