Skip to content

Commit bb8d6a0

Browse files
authored
[3.14] Improve hash() builtin docstring with caveats. (GH-125229) (#149054)
Improve `hash()` builtin docstring with caveats. Mention its return type and that the value can be expected to change between processes (hash randomization). Why? The `hash` builtin gets reached for and used by a lot of people whether it is the right tool or not. IDEs surface docstrings and people use pydoc and `help(hash)`. (cherry picked from commit 665b7df)
1 parent f9140e2 commit bb8d6a0

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Python/bltinmodule.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,15 +1763,17 @@ hash as builtin_hash
17631763
obj: object
17641764
/
17651765
1766-
Return the hash value for the given object.
1766+
Return the integer hash value for the given object.
17671767
1768-
Two objects that compare equal must also have the same hash value, but the
1769-
reverse is not necessarily true.
1768+
Two objects that compare equal must also have the same hash value, but
1769+
the reverse is not necessarily true. Hash values may differ between
1770+
Python processes. Not all objects are hashable; calling hash() on an
1771+
unhashable object raises TypeError.
17701772
[clinic start generated code]*/
17711773

17721774
static PyObject *
17731775
builtin_hash(PyObject *module, PyObject *obj)
1774-
/*[clinic end generated code: output=237668e9d7688db7 input=58c48be822bf9c54]*/
1776+
/*[clinic end generated code: output=237668e9d7688db7 input=70a242ff65f6717c]*/
17751777
{
17761778
Py_hash_t x;
17771779

Python/clinic/bltinmodule.c.h

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)