classification
Title: hashable documentation error
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: asvetlov, docs@python, ezio.melotti, max, python-dev
Priority: normal Keywords:

Created on 2012-10-04 11:37 by max, last changed 2013-02-01 03:22 by ezio.melotti. This issue is now closed.

Messages (4)
msg171935 - (view) Author: Max (max) * Date: 2012-10-04 11:37
http://docs.python.org/dev/glossary.html?highlight=hashable says:

Objects which are instances of user-defined classes are hashable by default; they all compare unequal, and their hash value is their id().

Since x == x returns True by default, so "they all compare unequal" isn't quite right.

In addition, both the above paragraph and http://docs.python.org/dev/reference/datamodel.html?highlight=__eq__#object.__hash__ say:

User-defined classes have __eq__() and __hash__() methods by default; with them, all objects compare unequal (except with themselves) and x.__hash__() returns an appropriate value such that x == y implies both that x is y and hash(x) == hash(y).

This is correct, but may leave some confusion with the reader about what happens to a subclass of a built-in class (which doesn't use the default behavior, but instead simply inherits the parent's __hash__ and __eq__).
msg172113 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-10-05 18:57
Please write what exact text you want to see in documentation.
msg181060 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-02-01 03:20
New changeset 79a021beaf58 by Ezio Melotti in branch '2.7':
#16128: clarify that instances of user-defined classes compare equal with themselves.
http://hg.python.org/cpython/rev/79a021beaf58

New changeset e84c5cf92b6f by Ezio Melotti in branch '3.2':
#16128: clarify that instances of user-defined classes compare equal with themselves.
http://hg.python.org/cpython/rev/e84c5cf92b6f

New changeset d9255c100971 by Ezio Melotti in branch '3.3':
#16128: merge with 3.2.
http://hg.python.org/cpython/rev/d9255c100971

New changeset 1890c63f6153 by Ezio Melotti in branch 'default':
#16128: merge with 3.3.
http://hg.python.org/cpython/rev/1890c63f6153
msg181062 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-02-01 03:22
I addressed the first comment.  The paragraph in datamodel.html looks ok to me, so I left it unchanged.  Feel free to reopen the issue if you have a specific suggestion that could improve that section.
History
Date User Action Args
2013-02-01 03:22:59ezio.melottisetstatus: open -> closed

assignee: docs@python -> ezio.melotti
versions: + Python 2.7, Python 3.3, Python 3.4
nosy: + ezio.melotti

messages: + msg181062
resolution: fixed
stage: resolved
2013-02-01 03:20:41python-devsetnosy: + python-dev
messages: + msg181060
2012-10-05 18:57:42asvetlovsetnosy: + asvetlov
messages: + msg172113
2012-10-04 11:37:14maxcreate