Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 45441:e47385ef4e17
grep: fix hash(linestate) to not include linenum
linestate.__eq__() just compares the line values whereas __hash__() does
hash both self.line and self.linenum, which violates the rule. __hash__()
was added at fb502719c75c, "python 2.6 compatibility: add __hash__ to
classes that have __eq__" with no additional remarks, so this would probably
be a simple mistake.
The test output changed because difflib.SequenceMatcher() internally uses
a dict. As you can see, the line "export" is unchanged at the revision 2,
so the new output is correct.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 09 Sep 2020 11:41:18 +0900 |
parents | 0652a533fe3c |
children | 453bc6ca9ab2 |
comparison
equal
deleted
inserted
replaced
45440:9c8d2cf7f591 | 45441:e47385ef4e17 |
---|---|
3398 self.linenum = linenum | 3398 self.linenum = linenum |
3399 self.colstart = colstart | 3399 self.colstart = colstart |
3400 self.colend = colend | 3400 self.colend = colend |
3401 | 3401 |
3402 def __hash__(self): | 3402 def __hash__(self): |
3403 return hash((self.linenum, self.line)) | 3403 return hash(self.line) |
3404 | 3404 |
3405 def __eq__(self, other): | 3405 def __eq__(self, other): |
3406 return self.line == other.line | 3406 return self.line == other.line |
3407 | 3407 |
3408 def findpos(self): | 3408 def findpos(self): |