summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-08-24 07:33:06 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-08-24 07:33:06 (GMT)
commite87ab3fefed00618992f5fe60a95ec9487e6303f (patch)
tree60598399122a01dffbe0134621b368aa54253eaf
parentbf935fde1550b768d9fb14cec230d1e79a5212c2 (diff)
downloadcpython-e87ab3fefed00618992f5fe60a95ec9487e6303f.zip
cpython-e87ab3fefed00618992f5fe60a95ec9487e6303f.tar.gz
cpython-e87ab3fefed00618992f5fe60a95ec9487e6303f.tar.bz2
Removed < <= > >= from the API. Implemented as comparisons of the
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.
-rw-r--r--Doc/lib/libsets.tex5
-rw-r--r--Lib/sets.py19
-rw-r--r--Lib/test/test_sets.py4
3 files changed, 5 insertions, 23 deletions
diff --git a/Doc/lib/libsets.tex b/Doc/lib/libsets.tex
index 5f199a0..8ce62c889 100644
--- a/Doc/lib/libsets.tex
+++ b/Doc/lib/libsets.tex
@@ -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}:
diff --git a/Lib/sets.py b/Lib/sets.py
index 09d9918..d422591 100644
--- a/Lib/sets.py
+++ b/Lib/sets.py
@@ -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):
diff --git a/Lib/test/test_sets.py b/Lib/test/test_sets.py
index 9ff98a6..65b48e2 100644
--- a/Lib/test/test_sets.py
+++ b/Lib/test/test_sets.py
@@ -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