baseset: stop inheriting from built-in list class
authorPierre-Yves David <pierre-yves.david@fb.com>
Mon, 06 Oct 2014 11:03:30 -0700
changeset 22825 0e8bb81b58b9
parent 22824 9271630f4720
child 22826 4ffb327e4719
baseset: stop inheriting from built-in list class The baseset is doing more and more smartset magic and using its list-like property less and less. So we store the list of revisions in an explicit attribute and stop inheriting. This requires reimplementing some basic methods.
mercurial/revset.py
--- a/mercurial/revset.py	Tue Oct 07 00:38:14 2014 -0700
+++ b/mercurial/revset.py	Mon Oct 06 11:03:30 2014 -0700
@@ -2320,14 +2320,16 @@
             kwargs['ascending'] = False
         return filteredset(self, condition, **kwargs)
 
-class baseset(list, abstractsmartset):
+class baseset(abstractsmartset):
     """Basic data structure that represents a revset and contains the basic
     operation that it should be able to perform.
 
     Every method in this class should be implemented by any smartset class.
     """
     def __init__(self, data=()):
-        super(baseset, self).__init__(data)
+        if not isinstance(data, list):
+            data = list(data)
+        self._list = data
         self._set = None
 
     def set(self):
@@ -2346,7 +2348,19 @@
         return self.set().__contains__
 
     def __nonzero__(self):
-        return bool(len(self))
+        return bool(self._list)
+
+    def sort(self, reverse=False):
+        self._list.sort(reverse=reverse)
+
+    def reverse(self):
+        self._list.reverse()
+
+    def __iter__(self):
+        return iter(self._list)
+
+    def __len__(self):
+        return len(self._list)
 
     def __sub__(self, other):
         """Returns a new object with the substraction of the two collections.
@@ -2389,12 +2403,12 @@
 
     def first(self):
         if self:
-            return self[0]
+            return self._list[0]
         return None
 
     def last(self):
         if self:
-            return self[-1]
+            return self._list[-1]
         return None
 
 class filteredset(abstractsmartset):