diff -r 9037d09ed87c -r 1c765dc90c21 eric6/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py --- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py Sat Apr 03 15:09:56 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py Sat Apr 03 16:02:33 2021 +0200 @@ -7,7 +7,7 @@ Module implementing a checker for function type annotations. """ -import sys +import copy import ast import AstUtilities @@ -32,12 +32,9 @@ ## Annotation Complexity "A891", - - ## Syntax Error - "A999", ] - def __init__(self, source, filename, select, ignore, expected, repeat, + def __init__(self, source, filename, tree, select, ignore, expected, repeat, args): """ Constructor @@ -46,6 +43,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 @@ -63,6 +62,7 @@ self.__repeat = repeat self.__filename = filename self.__source = source[:] + self.__tree = copy.deepcopy(tree) self.__args = args # statistics counters @@ -141,29 +141,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, - 'A999', exc_type.__name__, exc.args[0]) - - def __generateTree(self): - """ - Private method to generate an AST for our source. - - @return generated AST - @rtype ast.Module - """ - return ast.parse("".join(self.__source), self.__filename) - def run(self): """ Public method to check the given source against annotation issues. @@ -176,12 +153,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()