changeset 8312:31250d5e3c6a

vcs: avoid node base class knowledge of sub classes Pytype very reasonably got confused over the sub class property references in the base class. Fixed by moving base class specific parts of comparison to the sub classes and calling the base class. With .content only referenced in FileNode, there is even less need for an explicitly failing .content getter for DirNode.
author Mads Kiilerich <mads@kiilerich.com>
date Sat, 28 Mar 2020 21:21:47 +0100
parents 9757ad98ea09
children 4bc712f1ec93
files kallithea/lib/vcs/nodes.py
diffstat 1 files changed, 29 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/nodes.py	Sat Mar 28 21:07:08 2020 +0100
+++ b/kallithea/lib/vcs/nodes.py	Sat Mar 28 21:21:47 2020 +0100
@@ -135,13 +135,6 @@
             return False
         if self.path != other.path:
             return False
-        if self.is_file():
-            return self.content == other.content
-        else:
-            # For DirNode's check without entering each dir
-            self_nodes_paths = list(sorted(n.path for n in self.nodes))
-            other_nodes_paths = list(sorted(n.path for n in self.nodes))
-            return self_nodes_paths == other_nodes_paths
 
     def __lt__(self, other):
         if self.kind < other.kind:
@@ -152,13 +145,6 @@
             return True
         if self.path > other.path:
             return False
-        if self.is_file():
-            return self.content < other.content
-        else:
-            # For DirNode's check without entering each dir
-            self_nodes_paths = list(sorted(n.path for n in self.nodes))
-            other_nodes_paths = list(sorted(n.path for n in self.nodes))
-            return self_nodes_paths < other_nodes_paths
 
     def __repr__(self):
         return '<%s %r>' % (self.__class__.__name__, self.path)
@@ -247,6 +233,18 @@
         self._content = content
         self._mode = mode or 0o100644
 
+    def __eq__(self, other):
+        eq = super(FileNode, self).__eq__(other)
+        if eq is not None:
+            return eq
+        return self.content == other.content
+
+    def __lt__(self, other):
+        lt = super(FileNode, self).__lt__(other)
+        if lt is not None:
+            return lt
+        return self.content < other.content
+
     @LazyProperty
     def mode(self):
         """
@@ -465,10 +463,23 @@
         self.changeset = changeset
         self._nodes = nodes
 
-    @LazyProperty
-    def content(self):
-        raise NodeError("%s represents a dir and has no ``content`` attribute"
-            % self)
+    def __eq__(self, other):
+        eq = super(DirNode, self).__eq__(other)
+        if eq is not None:
+            return eq
+        # check without entering each dir
+        self_nodes_paths = list(sorted(n.path for n in self.nodes))
+        other_nodes_paths = list(sorted(n.path for n in self.nodes))
+        return self_nodes_paths == other_nodes_paths
+
+    def __lt__(self, other):
+        lt = super(DirNode, self).__lt__(other)
+        if lt is not None:
+            return lt
+        # check without entering each dir
+        self_nodes_paths = list(sorted(n.path for n in self.nodes))
+        other_nodes_paths = list(sorted(n.path for n in self.nodes))
+        return self_nodes_paths < other_nodes_paths
 
     @LazyProperty
     def nodes(self):