diff -r 9037d09ed87c -r 1c765dc90c21 eric6/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py --- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py Sat Apr 03 15:09:56 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py Sat Apr 03 16:02:33 2021 +0200 @@ -8,7 +8,7 @@ """ import ast -import sys +import copy from .SimplifyNodeVisitor import SimplifyNodeVisitor @@ -32,7 +32,8 @@ "Y301", ] - def __init__(self, source, filename, selected, ignored, expected, repeat): + def __init__(self, source, filename, tree, selected, ignored, expected, + repeat): """ Constructor @@ -40,6 +41,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 selected list of selected codes @type list of str @param ignored list of codes to be ignored @@ -55,6 +58,7 @@ self.__repeat = repeat self.__filename = filename self.__source = source[:] + self.__tree = copy.deepcopy(tree) # statistics counters self.counters = {} @@ -114,29 +118,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, - 'M901', exc_type.__name__, exc.args[0]) - - def __generateTree(self): - """ - Private method to generate an AST for our source. - - @return generated AST - @rtype ast.AST - """ - return ast.parse("".join(self.__source), self.__filename) - def run(self): """ Public method to check the given source against functions @@ -150,12 +131,6 @@ # don't do anything, if no codes were selected return - try: - self.__tree = self.__generateTree() - except (SyntaxError, TypeError): - self.__reportInvalidSyntax() - return - # Add parent information for node in ast.walk(self.__tree): for child in ast.iter_child_nodes(node):