aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/tree.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-05 00:21:35 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-05 00:21:35 -0500
commit282d5cf934eec5c0ae02a01c345c38d0ad7c9fa7 (patch)
tree2bcfa1465362f60136f040d28f3f1d3a7e0d8a07 /libbe/tree.py
parente023e7b980f8cfb4c02a0442a39774311e1c5a99 (diff)
downloadbugseverywhere-282d5cf934eec5c0ae02a01c345c38d0ad7c9fa7.tar.gz
Add __eq__ and __ne__ methods to Tree.
This fixes a bug introduced by revision-id: wking@drexel.edu-20091205034412-8apqxq8zqim48tf7 committer: W. Trevor King <wking@drexel.edu> timestamp: Fri 2009-12-04 22:44:12 -0500 message: Use __cmp__ instead of __eq__ for Tree comparison. When I made that commit, I'd forgotten that Tree inherits an __eq__ method from list, so it won't fall back to the __cmp__ method to determine equality. The new __eq__ and __ne__ methods use __cmp__ internally, so further subclasses (e.g. Comment) only need to override __cmp__. Of course, list also defines __ge__, __gt__, __le__, __lt__, ... which I don't bother with, so stay away from TreeA > TreeB and the like.
Diffstat (limited to 'libbe/tree.py')
-rw-r--r--libbe/tree.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/libbe/tree.py b/libbe/tree.py
index d3f6bcd..1daac44 100644
--- a/libbe/tree.py
+++ b/libbe/tree.py
@@ -87,6 +87,12 @@ class Tree(list):
def __cmp__(self, other):
return cmp(id(self), id(other))
+ def __eq__(self, other):
+ return self.__cmp__(other) == 0
+
+ def __ne__(self, other):
+ return self.__cmp__(other) != 0
+
def branch_len(self):
"""
Exhaustive search every time == SLOW.