Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/context.py @ 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 | 90a4329a6b4a |
children | 0c611355481b |
comparison
equal
deleted
inserted
replaced
6468:af2edc9c5bb9 | 6469:fb502719c75c |
---|---|
31 def __str__(self): | 31 def __str__(self): |
32 return short(self.node()) | 32 return short(self.node()) |
33 | 33 |
34 def __repr__(self): | 34 def __repr__(self): |
35 return "<changectx %s>" % str(self) | 35 return "<changectx %s>" % str(self) |
36 | |
37 def __hash__(self): | |
38 try: | |
39 return hash(self._rev) | |
40 except AttributeError: | |
41 return id(self) | |
36 | 42 |
37 def __eq__(self, other): | 43 def __eq__(self, other): |
38 try: | 44 try: |
39 return self._rev == other._rev | 45 return self._rev == other._rev |
40 except AttributeError: | 46 except AttributeError: |
208 return "%s@%s" % (self.path(), short(self.node())) | 214 return "%s@%s" % (self.path(), short(self.node())) |
209 | 215 |
210 def __repr__(self): | 216 def __repr__(self): |
211 return "<filectx %s>" % str(self) | 217 return "<filectx %s>" % str(self) |
212 | 218 |
219 def __hash__(self): | |
220 try: | |
221 return hash((self._path, self._fileid)) | |
222 except AttributeError: | |
223 return id(self) | |
224 | |
213 def __eq__(self, other): | 225 def __eq__(self, other): |
214 try: | 226 try: |
215 return (self._path == other._path | 227 return (self._path == other._path |
216 and self._fileid == other._fileid) | 228 and self._fileid == other._fileid) |
217 except AttributeError: | 229 except AttributeError: |