--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py Fri Jun 07 13:51:43 2024 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py Sat Jun 08 15:01:47 2024 +0200 @@ -201,6 +201,13 @@ """ from .AnnotationsFunctionVisitor import FunctionVisitor + # Type ignores are provided by ast at the module level & we'll need them later + # when deciding whether or not to emit errors for a given function + typeIgnoreLineno = {ti.lineno for ti in self.__tree.type_ignores} + hasMypyIgnoreErrors = ( + any("# mypy: ignore-errors" in line for line in self.__source[:5]) + ) + suppressNoneReturning = self.__args.get( "SuppressNoneReturning", AnnotationsCheckerDefaultArgs["SuppressNoneReturning"], @@ -220,6 +227,9 @@ allowStarArgAny = self.__args.get( "AllowStarArgAny", AnnotationsCheckerDefaultArgs["AllowStarArgAny"] ) + respectTypeIgnore = self.__args.get( + "RespectTypeIgnore", AnnotationsCheckerDefaultArgs["RespectTypeIgnore"] + ) # Store decorator lists as sets for easier lookup dispatchDecorators = set( @@ -285,6 +295,21 @@ if function.hasDecorator(overloadDecorators): lastOverloadDecoratedFunctionName = function.name + # Optionally respect a 'type: ignore' comment + # These are considered at the function level & tags are not considered + if respectTypeIgnore: + if function.lineno in typeIgnoreLineno: + # function-level ignore + continue + elif ( + any(lineno in typeIgnoreLineno for lineno in range(1, 6)) + or hasMypyIgnoreErrors + ): + # module-level ignore + # lineno from ast is 1-indexed + # check first five lines + continue + # Record explicit errors for arguments that are missing annotations for arg in function.getMissedAnnotations(): # Check for type comments here since we're not considering them as