changeset 8311:9757ad98ea09

vcs: simplify nodes kind handling Avoid pytype's very reasonable confusion over the _kind handling. Node.kind is actually only ever set in __init__, so there is not much need for a paranoid setter.
author Mads Kiilerich <mads@kiilerich.com>
date Sat, 28 Mar 2020 21:07:08 +0100
parents d6ccf6a9fd11
children 31250d5e3c6a
files kallithea/lib/vcs/nodes.py kallithea/tests/vcs/test_nodes.py
diffstat 2 files changed, 5 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/nodes.py	Sat Mar 28 15:29:58 2020 +0100
+++ b/kallithea/lib/vcs/nodes.py	Sat Mar 28 21:07:08 2020 +0100
@@ -128,24 +128,10 @@
         """
         return self.path.rstrip('/').split('/')[-1]
 
-    def _get_kind(self):
-        return self._kind
-
-    def _set_kind(self, kind):
-        if hasattr(self, '_kind'):
-            raise NodeError("Cannot change node's kind")
-        else:
-            self._kind = kind
-            # Post setter check (path's trailing slash)
-            if self.path.endswith('/'):
-                raise NodeError("Node's path cannot end with slash")
-
-    kind = property(_get_kind, _set_kind)
-
     def __eq__(self, other):
         if type(self) is not type(other):
             return False
-        if self._kind != other._kind:
+        if self.kind != other.kind:
             return False
         if self.path != other.path:
             return False
@@ -158,9 +144,9 @@
             return self_nodes_paths == other_nodes_paths
 
     def __lt__(self, other):
-        if self._kind < other._kind:
+        if self.kind < other.kind:
             return True
-        if self._kind > other._kind:
+        if self.kind > other.kind:
             return False
         if self.path < other.path:
             return True
@@ -587,7 +573,7 @@
 
     def __init__(self, name, url, changeset=None, alias=None):
         # Note: Doesn't call Node.__init__!
-        self.path = name
+        self.path = name.rstrip('/')
         self.kind = NodeKind.SUBMODULE
         self.alias = alias
         # we have to use emptyChangeset here since this can point to svn/git/hg
--- a/kallithea/tests/vcs/test_nodes.py	Sat Mar 28 15:29:58 2020 +0100
+++ b/kallithea/tests/vcs/test_nodes.py	Sat Mar 28 21:07:08 2020 +0100
@@ -49,11 +49,6 @@
         with pytest.raises(NodeError):
             Node('', NodeKind.FILE)
 
-    def test_kind_setter(self):
-        node = Node('', NodeKind.DIR)
-        with pytest.raises(NodeError):
-            setattr(node, 'kind', NodeKind.FILE)
-
     def _test_parent_path(self, node_path, expected_parent_path):
         """
         Tests if node's parent path are properly computed.
@@ -104,7 +99,7 @@
         node = DirNode('any_dir')
 
         assert node.is_dir()
-        with pytest.raises(NodeError):
+        with pytest.raises(AttributeError):  # Note: this used to raise NodeError
             getattr(node, 'content')
 
     def test_dir_node_iter(self):