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

branch
server
changeset 10759
aeb98b3fa008
parent 10754
6faecb62f3a4
child 10760
f702f6781b05
equal deleted inserted replaced
10752:3cf5ee0c3e9f 10759:aeb98b3fa008
190 check() 190 check()
191 191
192 ####################################################################### 192 #######################################################################
193 ## Annotations 193 ## Annotations
194 ## 194 ##
195 ## adapted from: flake8-annotations v3.0.1 195 ## adapted from: flake8-annotations v3.1.1
196 ####################################################################### 196 #######################################################################
197 197
198 def __checkFunctionAnnotations(self): 198 def __checkFunctionAnnotations(self):
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
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 )
203 210
204 suppressNoneReturning = self.__args.get( 211 suppressNoneReturning = self.__args.get(
205 "SuppressNoneReturning", 212 "SuppressNoneReturning",
206 AnnotationsCheckerDefaultArgs["SuppressNoneReturning"], 213 AnnotationsCheckerDefaultArgs["SuppressNoneReturning"],
207 ) 214 )
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