changeset 6469:fb502719c75c

python 2.6 compatibility: add __hash__ to classes that have __eq__
author Paul Moore <p.f.moore@gmail.com>
date Fri, 04 Apr 2008 22:41:17 +0200
parents af2edc9c5bb9
children ac0bcd951c2c
files mercurial/commands.py mercurial/context.py
diffstat 2 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Apr 04 22:18:38 2008 +0200
+++ b/mercurial/commands.py	Fri Apr 04 22:41:17 2008 +0200
@@ -1047,6 +1047,9 @@
             self.colstart = colstart
             self.colend = colend
 
+        def __hash__(self):
+            return hash((self.linenum, self.line))
+
         def __eq__(self, other):
             return self.line == other.line
 
--- a/mercurial/context.py	Fri Apr 04 22:18:38 2008 +0200
+++ b/mercurial/context.py	Fri Apr 04 22:41:17 2008 +0200
@@ -34,6 +34,12 @@
     def __repr__(self):
         return "<changectx %s>" % str(self)
 
+    def __hash__(self):
+        try:
+            return hash(self._rev)
+        except AttributeError:
+            return id(self)
+
     def __eq__(self, other):
         try:
             return self._rev == other._rev
@@ -210,6 +216,12 @@
     def __repr__(self):
         return "<filectx %s>" % str(self)
 
+    def __hash__(self):
+        try:
+            return hash((self._path, self._fileid))
+        except AttributeError:
+            return id(self)
+
     def __eq__(self, other):
         try:
             return (self._path == other._path