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

branch
eric7
changeset 9278
36448ca469c2
parent 9277
471c5a263d53
child 9595
2bd590c40309
diff -r 471c5a263d53 -r 36448ca469c2 src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyNodeVisitor.py
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyNodeVisitor.py	Thu Jul 28 19:44:54 2022 +0200
+++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyNodeVisitor.py	Fri Jul 29 16:29:31 2022 +0200
@@ -242,7 +242,7 @@
         self.__check208(node)
 
         self.generic_visit(node)
-    
+
     def visit_Subscript(self, node):
         """
         Public method to process a Subscript node.
@@ -286,17 +286,14 @@
     def __isConstantIncrease(self, expr):
         """
         Private method to check an expression for being a constant increase.
-        
+
         @param expr reference to the node to be checked
         @type ast.AugAssign
         @return flag indicating a constant increase
         @rtype bool
         """
         return isinstance(expr.op, ast.Add) and (
-            (
-                isinstance(expr.value, ast.Constant)
-                and expr.value.value == 1
-            )
+            (isinstance(expr.value, ast.Constant) and expr.value.value == 1)
             or (isinstance(expr.value, ast.Num) and expr.value.n == 1)
         )
 
@@ -434,7 +431,7 @@
     def __expressionUsesVariable(self, expr, var):
         """
         Private method to check, if a variable is used by an expression.
-        
+
         @param expr expression node to be checked
         @type ast.expr
         @param var variable name to be checked for
@@ -449,7 +446,7 @@
     def __bodyContainsContinue(self, stmts):
         """
         Private method to check, if a list of statements contain a 'continue' statement.
-        
+
         @param stmts list of statements
         @type list of ast.stmt
         @return flag indicating a continue statement
@@ -653,10 +650,7 @@
                 finallyReturn = stmt
                 break
 
-        if (
-            (tryHasReturn or exceptHasReturn)
-            and finallyHasReturn
-        ):
+        if (tryHasReturn or exceptHasReturn) and finallyHasReturn:
             self.__error(finallyReturn.lineno - 1, finallyReturn.col_offset, "Y107")
 
     def __check108(self, node):
@@ -693,7 +687,7 @@
         ):
             targetVar = node.body[0].targets[0]
             assign = unparse(targetVar)
-            
+
             # It's part of a bigger if-elseif block:
             if isinstance(node.parent, ast.If):
                 for n in node.parent.body:
@@ -703,7 +697,7 @@
                         and n.targets[0].id == targetVar.id
                     ):
                         return
-            
+
             body = unparse(node.body[0].value)
             cond = unparse(node.test)
             orelse = unparse(node.orelse[0].value)
@@ -794,7 +788,7 @@
                     check = f"not ({check})"
                 else:
                     if check.startswith("not "):
-                        check = check[len("not "):]
+                        check = check[len("not ") :]
                     else:
                         check = f"not {check}"
                 self.__error(
@@ -926,9 +920,7 @@
 
             for match in matches:
                 variable = unparse(match)
-                self.__error(
-                    match.lineno - 1, match.col_offset, "Y113", variable
-                )
+                self.__error(match.lineno - 1, match.col_offset, "Y113", variable)
 
     def __check114(self, node):
         """
@@ -1020,8 +1012,8 @@
             if isinstance(node.test.comparators[0], ast.Str):
                 value = (
                     bodyValueStr
-                    if bodyValueStr[0] == '"' and bodyValueStr[-1] == '"' else
-                    bodyValueStr[1:-1]
+                    if bodyValueStr[0] == '"' and bodyValueStr[-1] == '"'
+                    else bodyValueStr[1:-1]
                 )
                 keyValuePairs = {node.test.comparators[0].s: value}
             elif isinstance(node.test.comparators[0], ast.Num):
@@ -1233,7 +1225,7 @@
     def __check123(self, node):
         """
         Private method to check for complicated dictionary access with default value.
-        
+
         @param node reference to the AST node to be checked
         @type ast.If
         """
@@ -1290,8 +1282,15 @@
             valueStr = unparse(valueNode)
         else:
             return
-        self.__error(node.lineno - 1, node.col_offset, "Y123", valueStr, dictStr,
-                     keyStr, defaultStr)
+        self.__error(
+            node.lineno - 1,
+            node.col_offset,
+            "Y123",
+            valueStr,
+            dictStr,
+            keyStr,
+            defaultStr,
+        )
 
     def __check181(self, node):
         """
@@ -1721,7 +1720,7 @@
     def __check901(self, node):
         """
         Private method to check for unnecessary bool conversion.
-        
+
         @param node reference to the AST node to be checked
         @type ast.Call
         """
@@ -1738,7 +1737,7 @@
     def __check904(self, node):
         """
         Private method to check for dictionary initialization.
-        
+
         @param node reference to the AST node to be checked
         @type ast.Assign
         """
@@ -1761,7 +1760,7 @@
     def __check905(self, node):
         """
         Private method to check for list initialization by splitting a string.
-        
+
         @param node reference to the AST node to be checked
         @type ast.Call
         """
@@ -1782,7 +1781,7 @@
     def __check906(self, node):
         """
         Private method to check for unnecessary nesting of os.path.join().
-        
+
         @param node reference to the AST node to be checked
         @type ast.Call
         """
@@ -1830,20 +1829,19 @@
             names = getOsPathJoinArgs(node)
 
             actual = unparse(node)
-            expected = "os.path.join({0})".format(', '.join(names))
+            expected = "os.path.join({0})".format(", ".join(names))
             self.__error(node.lineno - 1, node.col_offset, "Y906", expected, actual)
 
     def __check907(self, node):
         """
         Private method to check for Union type annotation with None.
-        
+
         @param node reference to the AST node to be checked
         @type ast.Subscript
         """
-        if (isinstance(node.value, ast.Name) and node.value.id == "Union"):
-            if (
-                isinstance(node.slice, ast.Index)
-                and isinstance(node.slice.value, ast.Tuple)
+        if isinstance(node.value, ast.Name) and node.value.id == "Union":
+            if isinstance(node.slice, ast.Index) and isinstance(
+                node.slice.value, ast.Tuple
             ):
                 # Python 3.8
                 tupleVar = node.slice.value
@@ -1870,7 +1868,7 @@
     def __check909(self, node):
         """
         Private method to check for reflexive assignments.
-        
+
         @param node reference to the AST node to be checked
         @type ast.Assign
         """
@@ -1884,5 +1882,6 @@
             srccode = unparse(node)
             self.__error(node.lineno - 1, node.col_offset, "Y909", srccode)
 
+
 #
 # eflag: noqa = M891

eric ide

mercurial