src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py

branch
eric7
changeset 9277
471c5a263d53
parent 9221
bf71ee032bb4
child 9278
36448ca469c2
equal deleted inserted replaced
9276:e6748a5e24b9 9277:471c5a263d53
40 "Y118", 40 "Y118",
41 "Y119", 41 "Y119",
42 "Y120", 42 "Y120",
43 "Y121", 43 "Y121",
44 "Y122", 44 "Y122",
45 "Y123",
45 # Python-specifics not part of flake8-simplify 46 # Python-specifics not part of flake8-simplify
46 "Y181", 47 "Y181",
47 "Y182", 48 "Y182",
48 # Comparations 49 # Comparations
49 "Y201", 50 "Y201",
64 # Opinionated 65 # Opinionated
65 "Y301", 66 "Y301",
66 # General Code Style 67 # General Code Style
67 "Y401", 68 "Y401",
68 "Y402", 69 "Y402",
70 # Additional Checks
71 "Y901",
72 "Y904",
73 "Y905",
74 "Y906",
75 "Y907",
76 "Y909",
69 ] 77 ]
70 78
71 def __init__(self, source, filename, tree, selected, ignored, expected, repeat): 79 def __init__(self, source, filename, tree, selected, ignored, expected, repeat):
72 """ 80 """
73 Constructor 81 Constructor
165 if not self.__checkCodes: 173 if not self.__checkCodes:
166 # don't do anything, if no codes were selected 174 # don't do anything, if no codes were selected
167 return 175 return
168 176
169 # Add parent information 177 # Add parent information
170 for node in ast.walk(self.__tree): 178 self.__addMeta(self.__tree)
171 for child in ast.iter_child_nodes(node):
172 child.parent = node # type: ignore
173 179
174 visitor = SimplifyNodeVisitor(self.__error) 180 visitor = SimplifyNodeVisitor(self.__error)
175 visitor.visit(self.__tree) 181 visitor.visit(self.__tree)
182
183 def __addMeta(self, root, level=0):
184 """
185 Private method to amend the nodes of the given AST tree with backward and
186 forward references.
187
188 @param root reference to the root node of the tree
189 @type ast.AST
190 @param level nesting level (defaults to 0)
191 @type int (optional)
192 """
193 previousSibling = None
194 for node in ast.iter_child_nodes(root):
195 if level == 0:
196 node.parent = root
197 node.previous_sibling = previousSibling
198 node.next_sibling = None
199 if previousSibling:
200 node.previous_sibling.next_sibling = node
201 previousSibling = node
202 for child in ast.iter_child_nodes(node):
203 child.parent = node
204 self.__addMeta(node, level=level + 1)

eric ide

mercurial