Skip to content

Commit cf341ed

Browse files
gh-158798: Replace misleading "hashable collections" in object.__hash__ docs
1 parent 369d8bc commit cf341ed

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎Doc/reference/datamodel.rst‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,11 +2258,12 @@ Basic customization
22582258

22592259
If a class does not define an :meth:`__eq__` method it should not define a
22602260
:meth:`__hash__` operation either; if it defines :meth:`__eq__` but not
2261-
:meth:`__hash__`, its instances will not be usable as items in hashable
2262-
collections. If a class defines mutable objects and implements an
2263-
:meth:`__eq__` method, it should not implement :meth:`__hash__`, since the
2264-
implementation of :term:`hashable` collections requires that a key's hash value is
2265-
immutable (if the object's hash value changes, it will be in the wrong hash
2261+
:meth:`__hash__`, its instances will not be usable as items in collections
2262+
of :term:`hashable` objects. If a class defines mutable objects and
2263+
implements an :meth:`__eq__` method, it should not implement
2264+
:meth:`__hash__`, since the implementation of collections of
2265+
:term:`hashable` objects requires that a key's hash value is immutable
2266+
(if the object's hash value changes, it will be in the wrong hash
22662267
bucket).
22672268

22682269
User-defined classes have :meth:`__eq__` and :meth:`__hash__` methods

0 commit comments

Comments
 (0)