[Python-3000-checkins] r65811 - in python/branches/py3k: Doc/c-api/object.rst Doc/c-api/typeobj.rst

nick.coghlan python-3000-checkins at python.org
Mon Aug 18 15:18:16 CEST 2008


Author: nick.coghlan
Date: Mon Aug 18 15:18:16 2008
New Revision: 65811

Log:
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
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Doc/c-api/object.rst
   python/branches/py3k/Doc/c-api/typeobj.rst

Modified: python/branches/py3k/Doc/c-api/object.rst
==============================================================================
--- python/branches/py3k/Doc/c-api/object.rst	(original)
+++ python/branches/py3k/Doc/c-api/object.rst	Mon Aug 18 15:18:16 2008
@@ -257,6 +257,16 @@
    This is the equivalent of the Python expression ``hash(o)``.
 
 
+.. cfunction:: long PyObject_HashNotImplemented(PyObject *o)
+
+   Set a TypeError indicating that ``type(o)`` is not hashable and return ``-1``.
+   This function receives special treatment when stored in a ``tp_hash`` slot,
+   allowing a type to explicit indicate to the interpreter that it is not
+   hashable.
+
+   .. versionadded:: 2.6
+
+
 .. cfunction:: int PyObject_IsTrue(PyObject *o)
 
    Returns ``1`` if the object *o* is considered to be true, and ``0`` otherwise.

Modified: python/branches/py3k/Doc/c-api/typeobj.rst
==============================================================================
--- python/branches/py3k/Doc/c-api/typeobj.rst	(original)
+++ python/branches/py3k/Doc/c-api/typeobj.rst	Mon Aug 18 15:18:16 2008
@@ -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.


More information about the Python-3000-checkins mailing list