summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-01-18 16:09:55 (GMT)
committerGuido van Rossum <guido@python.org>2001-01-18 16:09:55 (GMT)
commit753a68e2cc671a525c02e4cd6d60412704275f3e (patch)
tree7b1c348ce9ed3bb7a068cb84570be3ac62217ade /Lib
parent9710bd5deb67e59205c861191331697f7b61f16a (diff)
downloadcpython-753a68e2cc671a525c02e4cd6d60412704275f3e.zip
cpython-753a68e2cc671a525c02e4cd6d60412704275f3e.tar.gz
cpython-753a68e2cc671a525c02e4cd6d60412704275f3e.tar.bz2
Bite the bullet: use rich comparisons here, too.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/UserList.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/Lib/UserList.py b/Lib/UserList.py
index e79faea..ee26589 100644
--- a/Lib/UserList.py
+++ b/Lib/UserList.py
@@ -12,11 +12,17 @@ class UserList:
else:
self.data = list(initlist)
def __repr__(self): return repr(self.data)
+ def __lt__(self, other): return self.data < self.__cast(other)
+ def __le__(self, other): return self.data <= self.__cast(other)
+ def __eq__(self, other): return self.data == self.__cast(other)
+ def __ne__(self, other): return self.data != self.__cast(other)
+ def __gt__(self, other): return self.data > self.__cast(other)
+ def __ge__(self, other): return self.data >= self.__cast(other)
+ def __cast(self, other):
+ if isinstance(other, UserList): return other.data
+ else: return other
def __cmp__(self, other):
- if isinstance(other, UserList):
- return cmp(self.data, other.data)
- else:
- return cmp(self.data, other)
+ raise RuntimeError, "UserList.__cmp__() is obsolete"
def __contains__(self, item): return item in self.data
def __len__(self): return len(self.data)
def __getitem__(self, i): return self.data[i]