--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Complexity/ComplexityChecker.py Fri Apr 02 11:59:41 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Complexity/ComplexityChecker.py Sat May 01 14:27:20 2021 +0200 @@ -7,24 +7,22 @@ Module implementing a checker for code complexity. """ -import sys +import copy import ast from .mccabe import PathGraphingAstVisitor -class ComplexityChecker(object): +class ComplexityChecker: """ Class implementing a checker for code complexity. """ 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() @@ -206,7 +187,7 @@ """ Constructor """ - super(LineComplexityVisitor, self).__init__() + super().__init__() self.__count = {} def visit(self, node):