[Python-checkins] CVS: python/dist/src/Lib UserList.py,1.13,1.14

Guido van Rossum gvanrossum@users.sourceforge.net
Thu, 18 Jan 2001 08:09:58 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv9241

Modified Files:
	UserList.py 
Log Message:
Bite the bullet: use rich comparisons here, too.


Index: UserList.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/UserList.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** UserList.py	2000/10/06 19:26:01	1.13
--- UserList.py	2001/01/18 16:09:55	1.14
***************
*** 13,21 ****
                  self.data = list(initlist)
      def __repr__(self): return repr(self.data)
      def __cmp__(self, other):
!         if isinstance(other, UserList):
!             return cmp(self.data, other.data)
!         else:
!             return cmp(self.data, other)
      def __contains__(self, item): return item in self.data
      def __len__(self): return len(self.data)
--- 13,27 ----
                  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):
!         raise RuntimeError, "UserList.__cmp__() is obsolete"
      def __contains__(self, item): return item in self.data
      def __len__(self): return len(self.data)