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

branch
eric7
changeset 9277
471c5a263d53
parent 9221
bf71ee032bb4
child 9278
36448ca469c2
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py	Thu Jul 28 14:19:57 2022 +0200
+++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py	Thu Jul 28 19:44:54 2022 +0200
@@ -42,6 +42,7 @@
         "Y120",
         "Y121",
         "Y122",
+        "Y123",
         # Python-specifics not part of flake8-simplify
         "Y181",
         "Y182",
@@ -66,6 +67,13 @@
         # General Code Style
         "Y401",
         "Y402",
+        # Additional Checks
+        "Y901",
+        "Y904",
+        "Y905",
+        "Y906",
+        "Y907",
+        "Y909",
     ]
 
     def __init__(self, source, filename, tree, selected, ignored, expected, repeat):
@@ -167,9 +175,30 @@
             return
 
         # Add parent information
-        for node in ast.walk(self.__tree):
-            for child in ast.iter_child_nodes(node):
-                child.parent = node  # type: ignore
+        self.__addMeta(self.__tree)
 
         visitor = SimplifyNodeVisitor(self.__error)
         visitor.visit(self.__tree)
+    
+    def __addMeta(self, root, level=0):
+        """
+        Private method to amend the nodes of the given AST tree with backward and
+        forward references.
+        
+        @param root reference to the root node of the tree
+        @type ast.AST
+        @param level nesting level (defaults to 0)
+        @type int (optional)
+        """
+        previousSibling = None
+        for node in ast.iter_child_nodes(root):
+            if level == 0:
+                node.parent = root
+            node.previous_sibling = previousSibling
+            node.next_sibling = None
+            if previousSibling:
+                node.previous_sibling.next_sibling = node
+            previousSibling = node
+            for child in ast.iter_child_nodes(node):
+                child.parent = node
+            self.__addMeta(node, level=level + 1)

eric ide

mercurial