eric6/Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py

changeset 7256
4ef3b78ebb4e
parent 7249
0bf517e60f54
child 7289
6f4761a73f5f
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py	Sat Sep 21 18:30:02 2019 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py	Sat Sep 21 20:30:56 2019 +0200
@@ -361,8 +361,9 @@
         copyrightAuthor = copyrightArgs.get(
             "Author",
             self.__defaultArgs["CopyrightChecker"]["Author"])
-        copyrightRegexStr = \
+        copyrightRegexStr = (
             r"Copyright\s+(\(C\)\s+)?(\d{{4}}\s+-\s+)?\d{{4}}\s+{author}"
+        )
         
         tocheck = max(1024, copyrightMinFileSize)
         topOfSource = source[:tocheck]
@@ -427,9 +428,11 @@
         Private method to check for print statements.
         """
         for node in ast.walk(self.__tree):
-            if (isinstance(node, ast.Call) and
-                getattr(node.func, 'id', None) == 'print') or \
-               (hasattr(ast, 'Print') and isinstance(node, ast.Print)):
+            if (
+                (isinstance(node, ast.Call) and
+                 getattr(node.func, 'id', None) == 'print') or
+                (hasattr(ast, 'Print') and isinstance(node, ast.Print))
+            ):
                 self.__error(node.lineno - 1, node.col_offset, "M801")
     
     def __checkTuple(self):
@@ -437,8 +440,10 @@
         Private method to check for one element tuples.
         """
         for node in ast.walk(self.__tree):
-            if isinstance(node, ast.Tuple) and \
-                    len(node.elts) == 1:
+            if (
+                isinstance(node, ast.Tuple) and
+                len(node.elts) == 1
+            ):
                 self.__error(node.lineno - 1, node.col_offset, "M811")
     
     def __checkFuture(self):
@@ -650,34 +655,44 @@
             if isinstance(node, ast.Assign):
                 # assign statement
                 for element in node.targets:
-                    if isinstance(element, ast.Name) and \
-                       element.id in self.__builtins:
+                    if (
+                        isinstance(element, ast.Name) and
+                        element.id in self.__builtins
+                    ):
                         value = node.value
-                        if isinstance(value, ast.Name) and \
-                           element.id in ignoreBuiltinAssignments and \
-                           value.id in ignoreBuiltinAssignments[element.id]:
+                        if (
+                            isinstance(value, ast.Name) and
+                            element.id in ignoreBuiltinAssignments and
+                            value.id in ignoreBuiltinAssignments[element.id]
+                        ):
                             # ignore compatibility assignments
                             continue
                         self.__error(element.lineno - 1, element.col_offset,
                                      "M131", element.id)
                     elif isinstance(element, (ast.Tuple, ast.List)):
                         for tupleElement in element.elts:
-                            if isinstance(tupleElement, ast.Name) and \
-                               tupleElement.id in self.__builtins:
+                            if (
+                                isinstance(tupleElement, ast.Name) and
+                                tupleElement.id in self.__builtins
+                            ):
                                 self.__error(tupleElement.lineno - 1,
                                              tupleElement.col_offset,
                                              "M131", tupleElement.id)
             elif isinstance(node, ast.For):
                 # for loop
                 target = node.target
-                if isinstance(target, ast.Name) and \
-                   target.id in self.__builtins:
+                if (
+                    isinstance(target, ast.Name) and
+                    target.id in self.__builtins
+                ):
                     self.__error(target.lineno - 1, target.col_offset,
                                  "M131", target.id)
                 elif isinstance(target, (ast.Tuple, ast.List)):
                     for element in target.elts:
-                        if isinstance(element, ast.Name) and \
-                           element.id in self.__builtins:
+                        if (
+                            isinstance(element, ast.Name) and
+                            element.id in self.__builtins
+                        ):
                             self.__error(element.lineno - 1,
                                          element.col_offset,
                                          "M131", element.id)
@@ -686,14 +701,18 @@
                 # (asynchronous) function definition
                 if sys.version_info >= (3, 0):
                     for arg in node.args.args:
-                        if isinstance(arg, ast.arg) and \
-                           arg.arg in self.__builtins:
+                        if (
+                            isinstance(arg, ast.arg) and
+                            arg.arg in self.__builtins
+                        ):
                             self.__error(arg.lineno - 1, arg.col_offset,
                                          "M132", arg.arg)
                 else:
                     for arg in node.args.args:
-                        if isinstance(arg, ast.Name) and \
-                           arg.id in self.__builtins:
+                        if (
+                            isinstance(arg, ast.Name) and
+                            arg.id in self.__builtins
+                        ):
                             self.__error(arg.lineno - 1, arg.col_offset,
                                          "M132", arg.id)
     
@@ -863,8 +882,10 @@
         if not all(isinstance(key, ast.Str) for key in node.keys):
             return False
         
-        if "__IGNORE_WARNING__" in self.__source[node.lineno - 1] or \
-           "__IGNORE_WARNING_M201__" in self.__source[node.lineno - 1]:
+        if (
+            "__IGNORE_WARNING__" in self.__source[node.lineno - 1] or
+            "__IGNORE_WARNING_M201__" in self.__source[node.lineno - 1]
+        ):
             return False
         
         lineNumbers = [key.lineno for key in node.keys]
@@ -895,8 +916,10 @@
         Private method to check the 'gettext' import statement.
         """
         for node in ast.walk(self.__tree):
-            if isinstance(node, ast.ImportFrom) and \
-               any(name.asname == '_' for name in node.names):
+            if (
+                isinstance(node, ast.ImportFrom) and
+                any(name.asname == '_' for name in node.names)
+            ):
                 self.__error(node.lineno - 1, node.col_offset, "M711",
                              node.names[0].name)
     
@@ -1158,8 +1181,10 @@
         @return flag indicating we are inside the extra keyword
         @rtype bool
         """
-        return self.__currentExtraKeyword is not None and \
+        return (
+            self.__currentExtraKeyword is not None and
             self.__currentExtraKeyword != node
+        )
     
     def __detectLoggingLevel(self, node):
         """
@@ -1231,8 +1256,11 @@
         for index, child in enumerate(ast.iter_child_nodes(node)):
             if index == 1:
                 self.__currentLoggingArgument = child
-            if index > 1 and isinstance(child, ast.keyword) and \
-               child.arg == "extra":
+            if (
+                index > 1 and
+                isinstance(child, ast.keyword) and
+                child.arg == "extra"
+            ):
                 self.__currentExtraKeyword = child
             
             super(LoggingVisitor, self).visit(child)
@@ -1308,8 +1336,7 @@
         """
         self.__nodeStack.append(node)
         self.__nodeWindow.append(node)
-        self.__nodeWindow = \
-            self.__nodeWindow[-BugBearVisitor.NodeWindowSize:]
+        self.__nodeWindow = self.__nodeWindow[-BugBearVisitor.NodeWindowSize:]
         
         super(BugBearVisitor, self).visit(node)
         
@@ -1405,8 +1432,11 @@
         if '.'.join(callPath) == 'sys.maxint' and sys.version_info >= (3, 0):
             self.violations.append((node, "M504"))
         
-        elif len(callPath) == 2 and callPath[1] == 'message' and \
-                sys.version_info >= (2, 6):
+        elif (
+            len(callPath) == 2 and
+            callPath[1] == 'message' and
+            sys.version_info >= (2, 6)
+        ):
             name = callPath[0]
             for elem in reversed(self.__nodeStack[:-1]):
                 if isinstance(elem, ast.ExceptHandler) and elem.name == name:
@@ -1429,8 +1459,10 @@
         
         elif len(node.targets) == 1:
             target = node.targets[0]
-            if isinstance(target, ast.Attribute) and \
-               isinstance(target.value, ast.Name):
+            if (
+                isinstance(target, ast.Attribute) and
+                isinstance(target.value, ast.Name)
+            ):
                 if (target.value.id, target.attr) == ('os', 'environ'):
                     self.violations.append((node, "M506"))
         
@@ -1454,8 +1486,10 @@
         @param node reference to the node to be processed
         @type ast.Assert
         """
-        if isinstance(node.test, ast.NameConstant) and \
-           node.test.value is False:
+        if (
+            isinstance(node.test, ast.NameConstant) and
+            node.test.value is False
+        ):
             self.violations.append((node, "M503"))
         
         self.generic_visit(node)

eric ide

mercurial