--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Sat Apr 03 15:09:56 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Sat Apr 03 16:02:33 2021 +0200 @@ -14,6 +14,7 @@ from string import Formatter from collections import defaultdict import tokenize +import copy import AstUtilities @@ -110,9 +111,6 @@ ## commented code "M891", - - ## syntax error - "M901", ] Formatter = Formatter() @@ -124,8 +122,8 @@ "credits", ] - def __init__(self, source, filename, select, ignore, expected, repeat, - args): + def __init__(self, source, filename, tree, select, ignore, expected, + repeat, args): """ Constructor @@ -133,6 +131,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 @@ -150,6 +150,7 @@ self.__repeat = repeat self.__filename = filename self.__source = source[:] + self.__tree = copy.deepcopy(tree) self.__args = args self.__pep3101FormatRegex = re.compile( @@ -267,29 +268,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 miscellaneous @@ -303,12 +281,6 @@ # don't do anything, if no codes were selected return - try: - self.__tree = self.__generateTree() - except (SyntaxError, TypeError): - self.__reportInvalidSyntax() - return - for check in self.__checkers: check() @@ -943,7 +915,7 @@ """ # step 1: generate an augmented node tree containing parent info # for each child node - tree = self.__generateTree() + tree = copy.deepcopy(self.__tree) for node in ast.walk(tree): for childNode in ast.iter_child_nodes(node): childNode._dtCheckerParent = node