Changeset - 9757ad98ea09
[Not reviewed]
default
0 2 0
Mads Kiilerich - 6 years ago 2020-03-28 21:07:08
mads@kiilerich.com
Grafted from: a234de987f8e
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.
2 files changed with 5 insertions and 24 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/nodes.py
Show inline comments
 
@@ -128,24 +128,10 @@ class Node(object):
 
        """
 
        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 @@ class Node(object):
 
            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 @@ class SubModuleNode(Node):
 

	
 
    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
kallithea/tests/vcs/test_nodes.py
Show inline comments
 
@@ -49,11 +49,6 @@ class TestNodeBasic(object):
 
        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 @@ class TestNodeBasic(object):
 
        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):
0 comments (0 inline, 0 general)