Mercurial > cpython-lru_cache-weakref
diff Doc/c-api/typeobj.rst @ 48741:7517bdcc769a
Merged revisions 65810 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65810 | nick.coghlan | 2008-08-18 23:14:22 +1000 (Mon, 18 Aug 2008) | 1 line
Issue 2235: document PyObject_HashNotImplemented
........
| author | Nick Coghlan <ncoghlan@gmail.com> |
|---|---|
| date | Mon, 18 Aug 2008 13:18:16 +0000 |
| parents | 6a7eb0b70198 |
| children | 3302045bae97 |
line wrap: on
line diff
--- a/Doc/c-api/typeobj.rst Mon Aug 18 12:31:52 2008 +0000 +++ b/Doc/c-api/typeobj.rst Mon Aug 18 13:18:16 2008 +0000 @@ -321,6 +321,14 @@ error occurs during the computation of the hash value, the function should set an exception and return ``-1``. + This field can be set explicitly to :cfunc:`PyObject_HashNotImplemented` to + block inheritance of the hash method from a parent type. This is interpreted + as the equivalent of ``__hash__ = None`` at the Python level, causing + ``isinstance(o, collections.Hashable)`` to correctly return ``False``. Note + that the converse is also true - setting ``__hash__ = None`` on a class at + the Python level will result in the ``tp_hash`` slot being set to + :cfunc:`PyObject_HashNotImplemented`. + When this field is not set, two possibilities exist: if the :attr:`tp_compare` and :attr:`tp_richcompare` fields are both *NULL*, a default hash value based on the object's address is returned; otherwise, a :exc:`TypeError` is raised.
