changeset 2141:647e222cd4ab

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.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Wed, 22 Mar 2017 05:15:49 +0100
parents 90f8f100dd58
children 7dc66a526b21
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)