]> granicus.if.org Git - python/commitdiff
Explicitly raise an exception in __cmp__ -- this clarifies that cmp()
authorGuido van Rossum <guido@python.org>
Tue, 14 Jan 2003 16:45:04 +0000 (16:45 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 14 Jan 2003 16:45:04 +0000 (16:45 +0000)
is not supported on sets.  (Unfortunately, sorting a list of sets may
still return random results because it uses < exclusively, but for
sets that inly implements a partial ordering.  Oh well.)

Lib/sets.py
Misc/NEWS

index 2605c98fd0982a9de6b986760b581397d00765d3..6d2c032066632229c76011ba9e105b3ecb6db31c 100644 (file)
@@ -102,6 +102,11 @@ class BaseSet(object):
         """
         return self._data.iterkeys()
 
+    # Three-way comparison is not supported
+
+    def __cmp__(self, other):
+        raise TypeError, "can't compare sets using cmp()"
+
     # Equality comparisons using the underlying dicts
 
     def __eq__(self, other):
index 5f415d49baf7ba3d11fd7e6a3e29e053b637d594..29411ec7d87419ac0034c3020b10fe8505ff4541 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -78,6 +78,10 @@ Extension modules
 Library
 -------
 
+- The sets module now raises TypeError in __cmp__, to clarify that
+  sets are not intended to be three-way-compared; the comparison
+  operators are overloaded as subset/superset tests.
+
 - Bastion.py and rexec.py are disabled.  These modules are not safe in
   Python 2.2. or 2.3.