From 282d5cf934eec5c0ae02a01c345c38d0ad7c9fa7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 5 Dec 2009 00:21:35 -0500 Subject: [PATCH] Add __eq__ and __ne__ methods to Tree. This fixes a bug introduced by revision-id: wking@drexel.edu-20091205034412-8apqxq8zqim48tf7 committer: W. Trevor King 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. --- libbe/tree.py | 6 ++++++ 1 file changed, 6 insertions(+) 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. -- 2.26.2