mirror of
https://github.com/python/cpython.git
synced 2026-04-26 22:01:08 +00:00
Improve hash() builtin docstring with caveats. (GH-125229)
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)`.
This commit is contained in:
parent
618b726d68
commit
665b7dfcfa
2 changed files with 12 additions and 8 deletions
10
Python/clinic/bltinmodule.c.h
generated
10
Python/clinic/bltinmodule.c.h
generated
|
|
@ -826,10 +826,12 @@ PyDoc_STRVAR(builtin_hash__doc__,
|
|||
"hash($module, obj, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return the hash value for the given object.\n"
|
||||
"Return the integer hash value for the given object.\n"
|
||||
"\n"
|
||||
"Two objects that compare equal must also have the same hash value, but the\n"
|
||||
"reverse is not necessarily true.");
|
||||
"Two objects that compare equal must also have the same hash value, but\n"
|
||||
"the reverse is not necessarily true. Hash values may differ between\n"
|
||||
"Python processes. Not all objects are hashable; calling hash() on an\n"
|
||||
"unhashable object raises TypeError.");
|
||||
|
||||
#define BUILTIN_HASH_METHODDEF \
|
||||
{"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__},
|
||||
|
|
@ -1380,4 +1382,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=1c3327da8885bb8e input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=f1fc836a63d89826 input=a9049054013a1b77]*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue