eric6/Plugins/CheckerPlugins/CodeStyleChecker/Complexity/ComplexityChecker.py

changeset 8198
1c765dc90c21
parent 8168
bdb0258faf42
child 8207
d359172d11be
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Complexity/ComplexityChecker.py	Sat Apr 03 15:09:56 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Complexity/ComplexityChecker.py	Sat Apr 03 16:02:33 2021 +0200
@@ -7,7 +7,7 @@
 Module implementing a checker for code complexity.
 """
 
-import sys
+import copy
 import ast
 
 from .mccabe import PathGraphingAstVisitor
@@ -20,11 +20,9 @@
     Codes = [
         "C101",
         "C111", "C112",
-        
-        "C901",
     ]
 
-    def __init__(self, source, filename, select, ignore, args):
+    def __init__(self, source, filename, tree, select, ignore, args):
         """
         Constructor
         
@@ -32,6 +30,8 @@
         @type list of str
         @param filename name of the source file
         @type str
+        @param tree AST tree of the source code
+        @type ast.Module
         @param select list of selected codes
         @type list of str
         @param ignore list of codes to be ignored
@@ -41,6 +41,7 @@
         """
         self.__filename = filename
         self.__source = source[:]
+        self.__tree = copy.deepcopy(tree)
         self.__select = tuple(select)
         self.__ignore = ('',) if select else tuple(ignore)
         self.__args = args
@@ -113,20 +114,6 @@
                 }
             )
     
-    def __reportInvalidSyntax(self):
-        """
-        Private method to report a syntax error.
-        """
-        exc_type, exc = sys.exc_info()[:2]
-        if len(exc.args) > 1:
-            offset = exc.args[1]
-            if len(offset) > 2:
-                offset = offset[1:3]
-        else:
-            offset = (1, 0)
-        self.__error(offset[0] - 1, offset[1] or 0,
-                     'C901', exc_type.__name__, exc.args[0])
-    
     def run(self):
         """
         Public method to check the given source for code complexity.
@@ -139,12 +126,6 @@
             # don't do anything, if no codes were selected
             return
         
-        try:
-            self.__tree = ast.parse("".join(self.__source), self.__filename)
-        except (SyntaxError, TypeError):
-            self.__reportInvalidSyntax()
-            return
-        
         for check in self.__checkers:
             check()
     

eric ide

mercurial