Use __cmp__ instead of __eq__ for Tree comparison.
authorW. Trevor King <wking@drexel.edu>
Sat, 5 Dec 2009 03:44:12 +0000 (22:44 -0500)
committerW. Trevor King <wking@drexel.edu>
Sat, 5 Dec 2009 03:44:12 +0000 (22:44 -0500)
This ensures that __ne__ will also work, and makes it easier to
subclass Tree.  For example, in the previous implementation you could
have
  >>> commA == commB
  False
  >>> cmp(commA, commB)
  0
if the comments had different ids, but equivalent content.

At the user-interface level, this removes some false "modified
comments" from `be diff`.

libbe/tree.py

index 8077da76d267a8433727f90260458931eb8fd9ab..d3f6bcd5d4f0b835d518ea256f9812882eeef1be 100644 (file)
@@ -84,8 +84,8 @@ class Tree(list):
     >>> a.has_descendant(a, match_self=True)
     True
     """
-    def __eq__(self, other):
-        return id(self) == id(other)
+    def __cmp__(self, other):
+        return cmp(id(self), id(other))
 
     def branch_len(self):
         """