diff -r a5c8bf5d1d5b Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst Wed Apr 18 18:59:56 2012 +0200 +++ b/Doc/reference/datamodel.rst Wed Apr 18 14:45:17 2012 -0700 @@ -1260,22 +1260,18 @@ by default; with them, all objects compare unequal (except with themselves) and ``x.__hash__()`` returns ``id(x)``. - Classes which inherit a :meth:`__hash__` method from a parent class but - change the meaning of :meth:`__eq__` such that the hash value returned is no - longer appropriate (e.g. by switching to a value-based concept of equality - instead of the default identity based equality) can explicitly flag - themselves as being unhashable by setting ``__hash__ = None`` in the class - definition. Doing so means that not only will instances of the class raise an - appropriate :exc:`TypeError` when a program attempts to retrieve their hash - value, but they will also be correctly identified as unhashable when checking - ``isinstance(obj, collections.Hashable)`` (unlike classes which define their - own :meth:`__hash__` to explicitly raise :exc:`TypeError`). + To suppress hash support, include :meth:``__hash__ = None`` in the class + definition; when `hash()` is called on instances of this class an + appropriate :exc:`TypeError` will be raised, and these instances will also + be correctly identified as unhashable when checking + ``isinstance(obj, collections.Hashable)``, unlike classes which define their + own :meth:`__hash__` to explicitly raise :exc:`TypeError`. - If a class that overrides :meth:`__eq__` needs to retain the implementation - of :meth:`__hash__` from a parent class, the interpreter must be told this - explicitly by setting ``__hash__ = .__hash__``. Otherwise the - inheritance of :meth:`__hash__` will be blocked, just as if :attr:`__hash__` - had been explicitly set to :const:`None`. + Classes which define :meth:`__eq__` but do not define :meth:`__hash__` + will have :meth:`__hash__` set to `None` impicitly. If a class that + overrides :meth:`__eq__` needs to retain the implementation of + :meth:`__hash__` from a parent class, the interpreter must be told this + explicitly by setting ``__hash__ = .__hash__``. .. note::