Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 753a68e

Browse files
committed
Bite the bullet: use rich comparisons here, too.
1 parent 9710bd5 commit 753a68e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/UserList.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ def __init__(self, initlist=None):
1212
else:
1313
self.data = list(initlist)
1414
def __repr__(self): return repr(self.data)
15+
def __lt__(self, other): return self.data < self.__cast(other)
16+
def __le__(self, other): return self.data <= self.__cast(other)
17+
def __eq__(self, other): return self.data == self.__cast(other)
18+
def __ne__(self, other): return self.data != self.__cast(other)
19+
def __gt__(self, other): return self.data > self.__cast(other)
20+
def __ge__(self, other): return self.data >= self.__cast(other)
21+
def __cast(self, other):
22+
if isinstance(other, UserList): return other.data
23+
else: return other
1524
def __cmp__(self, other):
16-
if isinstance(other, UserList):
17-
return cmp(self.data, other.data)
18-
else:
19-
return cmp(self.data, other)
25+
raise RuntimeError, "UserList.__cmp__() is obsolete"
2026
def __contains__(self, item): return item in self.data
2127
def __len__(self): return len(self.data)
2228
def __getitem__(self, i): return self.data[i]

0 commit comments

Comments
 (0)