]> granicus.if.org Git - python/commitdiff
SF bug #1179957: Missing def'n of equality for set elements
authorRaymond Hettinger <python@rcn.com>
Sun, 10 Apr 2005 17:32:35 +0000 (17:32 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 10 Apr 2005 17:32:35 +0000 (17:32 +0000)
Doc/lib/libsets.tex
Doc/lib/libstdtypes.tex

index 8085ab1d48eb6901dbbb832a36ac4e57796d548c..0cd5e2e2831572ab603a38a7733ad005e41a3775 100644 (file)
@@ -30,7 +30,10 @@ method but omits methods which alter the contents of the set. Both
 abstract class useful for determining whether something is a set:
 \code{isinstance(\var{obj}, BaseSet)}.
 
-The set classes are implemented using dictionaries.  As a result, sets
+The set classes are implemented using dictionaries.  Accordingly, the
+requirements for set elements are the same as those for dictionary keys;
+namely, that the element defines both \method{__eq__} and \method{__hash__}.
+As a result, sets
 cannot contain mutable elements such as lists or dictionaries.
 However, they can contain immutable collections such as tuples or
 instances of \class{ImmutableSet}.  For convenience in implementing
index c46451778cba6c2852d4c5321ce797d22298bbf8..03bccd94956c0f9cc19e161beca7d17fcb8d62ba 100644 (file)
@@ -1220,6 +1220,9 @@ Accordingly, sets do not implement the \method{__cmp__} method.
 Since sets only define partial ordering (subset relationships), the output
 of the \method{list.sort()} method is undefined for lists of sets.
 
+Set elements are like dictionary keys; they need to define both
+\method{__hash__} and \method{__eq__} methods.
+
 Binary operations that mix \class{set} instances with \class{frozenset}
 return the type of the first operand.  For example:
 \samp{frozenset('ab') | set('bc')} returns an instance of \class{frozenset}.