stablerange: have the class behave as a tuple
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Wed, 22 Mar 2017 05:15:49 +0100
changeset 2141 647e222cd4ab
parent 2140 90f8f100dd58
child 2142 7dc66a526b21
stablerange: have the class behave as a tuple If we want people to use a tuple, we should offer them a tuple. This should help update most of the code iteratively.
hgext3rd/evolve/stablerange.py
--- a/hgext3rd/evolve/stablerange.py	Wed Mar 22 05:44:39 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Wed Mar 22 05:15:49 2017 +0100
@@ -357,6 +357,15 @@
             raise NotImplementedError()
         return self.stablekey == other.stablekey
 
+    def __getitem__(self, idx):
+        """small helper function to prepare for the migration to tuple"""
+        if idx == 0:
+            return self.head
+        elif idx == 1:
+            return self.index
+        else:
+            raise IndexError(idx)
+
     @util.propertycache
     def _id(self):
         return hash(self.stablekey)