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.
This commit is contained in:
parent
bf935fde15
commit
e87ab3fefe
|
@ -100,9 +100,8 @@ the following operations:
|
||||||
\end{tableii}
|
\end{tableii}
|
||||||
|
|
||||||
In addition to the above operations, both \class{Set} and \class{ImmutableSet}
|
In addition to the above operations, both \class{Set} and \class{ImmutableSet}
|
||||||
support set to set comparison operators based on the contents of their
|
support set to set equality comparisons. Two sets are equal if and only if
|
||||||
internal dictionaries. Two sets are equal if and only if every element of
|
every element of each set is contained in the other.
|
||||||
each set is contained in the other.
|
|
||||||
|
|
||||||
The following table lists operations available in \class{ImmutableSet}
|
The following table lists operations available in \class{ImmutableSet}
|
||||||
but not found in \class{Set}:
|
but not found in \class{Set}:
|
||||||
|
|
19
Lib/sets.py
19
Lib/sets.py
|
@ -102,16 +102,7 @@ class BaseSet(object):
|
||||||
"""
|
"""
|
||||||
return self._data.iterkeys()
|
return self._data.iterkeys()
|
||||||
|
|
||||||
# Comparisons. Ordering is determined by the ordering of the
|
# Equality comparisons using the underlying dicts
|
||||||
# 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
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
self._binary_sanity_check(other)
|
self._binary_sanity_check(other)
|
||||||
|
@ -121,14 +112,6 @@ class BaseSet(object):
|
||||||
self._binary_sanity_check(other)
|
self._binary_sanity_check(other)
|
||||||
return self._data != other._data
|
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
|
# Copying operations
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
|
|
|
@ -419,12 +419,12 @@ class TestOnlySetsInBinaryOps(unittest.TestCase):
|
||||||
|
|
||||||
def test_cmp(self):
|
def test_cmp(self):
|
||||||
try:
|
try:
|
||||||
self.other < self.set
|
self.other == self.set
|
||||||
assert 0, "Comparison with non-set on left"
|
assert 0, "Comparison with non-set on left"
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
self.set >= self.other
|
self.set != self.other
|
||||||
assert 0, "Comparison with non-set on right"
|
assert 0, "Comparison with non-set on right"
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue