[issue4341] Update __hash__ doc

Terry J. Reedy report at bugs.python.org
Mon Nov 17 22:48:35 CET 2008


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

Language/data model/special method names/ __hash__

Sentence 1: "Called for the key object for dictionary operations, and by
the built-in function hash()."

Also called for the members of set and frozenset (and any other hashed
based collection).

Suggestion 1: "Called by the built-in function hash() and for operations
on members or keys of hashed collections. These currently include the
built-in classes set, frozenset, and dict."

Corresponding future-proof changes later in the text:

>From "its instances will not be usable as dictionary keys"

to "its instances will not be usable as hashable members or keys".

>From "since the dictionary implementation requires"

to "since hashable collection implementations require"
==============================

Sentence 2: "Should return an integer usable as a hash value for
dictionary operations."

I am confused by the qualification 'usable....'.  If it does not
qualify, it is meaningless and should be removed.  If it does qualify,
it should be replaced by what it means.

My impression is that integers of any value are usable since 2.5.

It is also my impression that 2.x specifically requires an int or long.
If so, "Should return an int or long integer." would be clearer.

For 3.0, I don't know what the boundaries are.  A float works, even if
not integral. [bug?] A Fraction does not, even if integral, even though
int(Fraction(n,1)) returns n.

----------
assignee: georg.brandl
components: Documentation
messages: 75984
nosy: georg.brandl, tjreedy
severity: normal
stage: needs patch
status: open
title: Update __hash__ doc
versions: Python 2.6, Python 3.0

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


More information about the Python-bugs-list mailing list