src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Annotations/AnnotationsChecker.py

branch
eric7
changeset 10753
031cfa81992a
parent 10439
21c28b0f9e41
child 10754
6faecb62f3a4
equal deleted inserted replaced
10751:d4dbb6b75bdc 10753:031cfa81992a
199 """ 199 """
200 Private method to check for function annotation issues. 200 Private method to check for function annotation issues.
201 """ 201 """
202 from .AnnotationsFunctionVisitor import FunctionVisitor 202 from .AnnotationsFunctionVisitor import FunctionVisitor
203 203
204 # Type ignores are provided by ast at the module level & we'll need them later
205 # when deciding whether or not to emit errors for a given function
206 typeIgnoreLineno = {ti.lineno for ti in self.__tree.type_ignores}
207 hasMypyIgnoreErrors = (
208 any("# mypy: ignore-errors" in line for line in self.__source[:5])
209 )
210
204 suppressNoneReturning = self.__args.get( 211 suppressNoneReturning = self.__args.get(
205 "SuppressNoneReturning", 212 "SuppressNoneReturning",
206 AnnotationsCheckerDefaultArgs["SuppressNoneReturning"], 213 AnnotationsCheckerDefaultArgs["SuppressNoneReturning"],
207 ) 214 )
208 suppressDummyArgs = self.__args.get( 215 suppressDummyArgs = self.__args.get(
217 mypyInitReturn = self.__args.get( 224 mypyInitReturn = self.__args.get(
218 "MypyInitReturn", AnnotationsCheckerDefaultArgs["MypyInitReturn"] 225 "MypyInitReturn", AnnotationsCheckerDefaultArgs["MypyInitReturn"]
219 ) 226 )
220 allowStarArgAny = self.__args.get( 227 allowStarArgAny = self.__args.get(
221 "AllowStarArgAny", AnnotationsCheckerDefaultArgs["AllowStarArgAny"] 228 "AllowStarArgAny", AnnotationsCheckerDefaultArgs["AllowStarArgAny"]
229 )
230 respectTypeIgnore = self.__args.get(
231 "RespectTypeIgnore", AnnotationsCheckerDefaultArgs["RespectTypeIgnore"]
222 ) 232 )
223 233
224 # Store decorator lists as sets for easier lookup 234 # Store decorator lists as sets for easier lookup
225 dispatchDecorators = set( 235 dispatchDecorators = set(
226 self.__args.get( 236 self.__args.get(
282 292
283 # If it's not, and it is overload decorated, store it for the next 293 # If it's not, and it is overload decorated, store it for the next
284 # iteration 294 # iteration
285 if function.hasDecorator(overloadDecorators): 295 if function.hasDecorator(overloadDecorators):
286 lastOverloadDecoratedFunctionName = function.name 296 lastOverloadDecoratedFunctionName = function.name
297
298 # Optionally respect a 'type: ignore' comment
299 # These are considered at the function level & tags are not considered
300 if respectTypeIgnore:
301 if function.lineno in typeIgnoreLineno:
302 # function-level ignore
303 continue
304 elif (
305 any(lineno in typeIgnoreLineno for lineno in range(1, 6))
306 or hasMypyIgnoreErrors
307 ):
308 # module-level ignore
309 # lineno from ast is 1-indexed
310 # check first five lines
311 continue
287 312
288 # Record explicit errors for arguments that are missing annotations 313 # Record explicit errors for arguments that are missing annotations
289 for arg in function.getMissedAnnotations(): 314 for arg in function.getMissedAnnotations():
290 # Check for type comments here since we're not considering them as 315 # Check for type comments here since we're not considering them as
291 # typed args 316 # typed args

eric ide

mercurial