mirror of
https://github.com/python/cpython.git
synced 2026-05-08 19:41:06 +00:00
[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 665b7dfcfa)
This commit is contained in:
parent
f9140e201c
commit
bb8d6a0863
2 changed files with 12 additions and 8 deletions
|
|
@ -1763,15 +1763,17 @@ hash as builtin_hash
|
|||
obj: object
|
||||
/
|
||||
|
||||
Return the hash value for the given object.
|
||||
Return the integer hash value for the given object.
|
||||
|
||||
Two objects that compare equal must also have the same hash value, but the
|
||||
reverse is not necessarily true.
|
||||
Two objects that compare equal must also have the same hash value, but
|
||||
the reverse is not necessarily true. Hash values may differ between
|
||||
Python processes. Not all objects are hashable; calling hash() on an
|
||||
unhashable object raises TypeError.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
builtin_hash(PyObject *module, PyObject *obj)
|
||||
/*[clinic end generated code: output=237668e9d7688db7 input=58c48be822bf9c54]*/
|
||||
/*[clinic end generated code: output=237668e9d7688db7 input=70a242ff65f6717c]*/
|
||||
{
|
||||
Py_hash_t x;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue