aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/util/tree.py
diff options
context:
space:
mode:
Diffstat (limited to 'libbe/util/tree.py')
-rw-r--r--libbe/util/tree.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/libbe/util/tree.py b/libbe/util/tree.py
index 5d0da49..61525aa 100644
--- a/libbe/util/tree.py
+++ b/libbe/util/tree.py
@@ -21,11 +21,13 @@
"""Define :py:class:`Tree`, a traversable tree structure.
"""
+import functools
import libbe
if libbe.TESTING:
import doctest
+@functools.total_ordering
class Tree(list):
"""A traversable tree structure.
@@ -78,7 +80,7 @@ class Tree(list):
Serialize the tree with depth marking branches.
>>> for depth,node in a.thread():
- ... print "%*s" % (2*depth+1, node.n)
+ ... print("%*s" % (2*depth+1, node.n))
a
b
d
@@ -93,7 +95,7 @@ class Tree(list):
branch splits.
>>> for depth,node in a.thread(flatten=True):
- ... print "%*s" % (2*depth+1, node.n)
+ ... print("%*s" % (2*depth+1, node.n))
a
b
d
@@ -115,14 +117,12 @@ class Tree(list):
>>> a.has_descendant(a, match_self=True)
True
"""
- def __cmp__(self, other):
- return (id(self) > id(other)) - (id(self) < id(other))
+ # TODO: is this correct? what has id() to do with the magnitude of an object?
+ def __lt__(self, other):
+ return id(self) < id(other)
def __eq__(self, other):
- return self.__cmp__(other) == 0
-
- def __ne__(self, other):
- return self.__cmp__(other) != 0
+ return id(self) == id(other)
def branch_len(self):
"""Return the largest number of nodes from root to leaf (inclusive).