Removed < <= > >= from the API. Implemented as comparisons of the
authorRaymond Hettinger <python@rcn.com>
Sat, 24 Aug 2002 07:33:06 +0000 (07:33 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 24 Aug 2002 07:33:06 +0000 (07:33 +0000)
underlying dictionaries, there were no reasonable use cases (lexicographic
sorting of a list of sets is somewhat esoteric).  Frees the operators
for other uses (such as strict subset and superset comparisons).

Updated documentation and test suite accordingly.

Doc/lib/libsets.tex
Lib/sets.py
Lib/test/test_sets.py

index 5f199a0ce10fff6f79c39b4ecbc6facb8cde8b02..8ce62c88980efcc5920265b07a2a38ad2e228250 100644 (file)
@@ -100,9 +100,8 @@ the following operations:
 \end{tableii}
 
 In addition to the above operations, both \class{Set} and \class{ImmutableSet}
-support set to set comparison operators based on the contents of their
-internal dictionaries.  Two sets are equal if and only if every element of
-each set is contained in the other.
+support set to set equality comparisons.  Two sets are equal if and only if
+every element of each set is contained in the other.
 
 The following table lists operations available in \class{ImmutableSet}
 but not found in \class{Set}:
index 09d9918c697ca732c173f0e532332ac3516526e4..d42259108cdb81695ca70d3ce7618c101d942f4d 100644 (file)
@@ -102,16 +102,7 @@ class BaseSet(object):
         """
         return self._data.iterkeys()
 
-    # Comparisons.  Ordering is determined by the ordering of the
-    # underlying dicts (which is consistent though unpredictable).
-
-    def __lt__(self, other):
-        self._binary_sanity_check(other)
-        return self._data < other._data
-
-    def __le__(self, other):
-        self._binary_sanity_check(other)
-        return self._data <= other._data
+    # Equality comparisons using the underlying dicts
 
     def __eq__(self, other):
         self._binary_sanity_check(other)
@@ -121,14 +112,6 @@ class BaseSet(object):
         self._binary_sanity_check(other)
         return self._data != other._data
 
-    def __gt__(self, other):
-        self._binary_sanity_check(other)
-        return self._data > other._data
-
-    def __ge__(self, other):
-        self._binary_sanity_check(other)
-        return self._data >= other._data
-
     # Copying operations
 
     def copy(self):
index 9ff98a6503c11008a4720b2a14b37575fd92f2af..65b48e2d8db9139963f378fcc3d8cc6870284886 100644 (file)
@@ -419,12 +419,12 @@ class TestOnlySetsInBinaryOps(unittest.TestCase):
 
     def test_cmp(self):
         try:
-            self.other < self.set
+            self.other == self.set
             assert 0, "Comparison with non-set on left"
         except TypeError:
             pass
         try:
-            self.set >= self.other
+            self.set != self.other
             assert 0, "Comparison with non-set on right"
         except TypeError:
             pass