# HG changeset patch # User Mads Kiilerich # Date 1585426028 -3600 # Node ID 9757ad98ea0986f48086251d1df3077341723941 # Parent d6ccf6a9fd1141e1a6808e0257028b88749851d1 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. diff -r d6ccf6a9fd11 -r 9757ad98ea09 kallithea/lib/vcs/nodes.py --- 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 diff -r d6ccf6a9fd11 -r 9757ad98ea09 kallithea/tests/vcs/test_nodes.py --- 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):