@@ -22,18 +22,20 @@ def get(self):
22
22
23
23
def set (self , new_value ):
24
24
"""Store provided value in this node"""
25
- if type (self ._value ) != type (new_value ):
26
- raise TypeError ("Cannot assign value with type '{}' to '{}' node" .format (type (new_value ).__name__ ,
27
- type (self ._value ).__name__ ))
25
+ if not isinstance (new_value , type (self ._value )):
26
+ new_type = type (new_value ).__name__
27
+ current_type = type (self ._value ).__name__
28
+ raise TypeError (
29
+ f"Cannot assign value with type '{ new_type } ' to '{ current_type } ' node" )
28
30
self ._value = new_value
29
31
30
32
def list (self ):
31
33
"""List names of the subnodes"""
32
34
names = map (lambda p : p [0 ], self ._subnodes )
33
35
index = 0
34
36
indexed_names = []
35
- for n in names :
36
- indexed_names .append (n if n is not None else index )
37
+ for name in names :
38
+ indexed_names .append (name if name is not None else index )
37
39
index += 1
38
40
return indexed_names
39
41
@@ -42,7 +44,7 @@ def append(self, node, name: str = None):
42
44
if node is None :
43
45
raise ValueError ("Cannot append None as node" )
44
46
if name is not None :
45
- if len ( name ) == 0 :
47
+ if not name :
46
48
raise NameError ("Invalid appended node name - empty" )
47
49
if self .get_node (name ) is not None :
48
50
raise NameError ("Node '{}' already exists" .format (name ))
@@ -52,9 +54,9 @@ def append(self, node, name: str = None):
52
54
def get_node (self , name : str = None , index : int = None ) -> Optional ['Node' ]:
53
55
"""Return subnode with provided name or index"""
54
56
if name is not None :
55
- for p in self ._subnodes :
56
- if p [0 ] == name :
57
- return p [1 ]
57
+ for name_node_pair in self ._subnodes :
58
+ if name_node_pair [0 ] == name :
59
+ return name_node_pair [1 ]
58
60
elif index is not None :
59
61
if 0 <= index < len (self ._subnodes ):
60
62
return self ._subnodes [index ][1 ]
@@ -153,7 +155,7 @@ def install_action(self, target: NodePath, action: Action):
153
155
self .create (NodePath .join (target , '@actions' , action .name ), action )
154
156
155
157
def find_first_in (self , candidate_paths : List [NodePath ]) -> Optional [Node ]:
156
- if candidate_paths is None or len ( candidate_paths ) == 0 :
158
+ if candidate_paths is None or not candidate_paths :
157
159
raise ValueError ("No candidate paths provided" )
158
160
for path in candidate_paths :
159
161
node = self ._resolve_optional_path (path )
@@ -177,10 +179,9 @@ def list_actions(self, path: NodePath) -> List[NodePath]:
177
179
action_paths = self .list (NodePath .join (path , '@actions' ))
178
180
action_paths = sorted (action_paths )
179
181
180
- if len ( path ) == 0 : # Root
182
+ if not path : # Root
181
183
return action_paths
182
- else :
183
- return action_paths + self .list_actions (path .base_path )
184
+ return action_paths + self .list_actions (path .base_path )
184
185
185
186
def install_global_type (self , node_type ):
186
187
self .install_type (NodePath ('.' ), node_type )
@@ -240,7 +241,7 @@ def _resolve_optional_path(self, path: NodePath, root: Node = None) -> Optional[
240
241
raise ValueError ("Could not resolve relative paths" )
241
242
root = self .root
242
243
assert root is not None
243
- if len ( path ) == 0 :
244
+ if not path :
244
245
return root
245
246
246
247
next_branch_name = path [0 ]
@@ -254,7 +255,7 @@ def _create_path(self, path: NodePath, root: Node = None) -> Node:
254
255
raise ValueError ("Could not resolve relative paths" )
255
256
root = self .root
256
257
assert root is not None
257
- if len ( path ) == 0 :
258
+ if not path :
258
259
return root
259
260
260
261
next_branch_name = path [0 ]
0 commit comments