Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0dbdab2

Browse files
committed
Add another usage note for collections.Set
1 parent 7aebb64 commit 0dbdab2

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Doc/library/collections.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ABC Inherits Abstract Methods Mixin M
5858
``insert``, ``remove``, and ``__iadd__``
5959
and ``__len__``
6060

61-
:class:`Set` \(1) \(2) :class:`Sized`, ``__len__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
61+
:class:`Set` :class:`Sized`, ``__len__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
6262
:class:`Iterable`, ``__iter__``, and ``__gt__``, ``__ge__``, ``__and__``, ``__or__``
6363
:class:`Container` ``__contains__`` ``__sub__``, ``__xor__``, and ``isdisjoint``
6464

@@ -118,6 +118,13 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
118118
semantics are fixed), redefine :meth:`__le__` and
119119
then the other operations will automatically follow suit.
120120

121+
(3)
122+
The :class:`Set` mixin provides a :meth:`_hash` method to compute a hash value
123+
for the set; however, :meth:`__hash__` is not defined because not all sets
124+
are hashable or immutable. To add set hashabilty using mixins,
125+
inherit from both :meth:`Set` and :meth:`Hashable`, then define
126+
``__hash__ = Set._hash``.
127+
121128
(For more about ABCs, see the :mod:`abc` module and :pep:`3119`.)
122129

123130

0 commit comments

Comments
 (0)