63 # collection of detected errors |
63 # collection of detected errors |
64 self.errors = [] |
64 self.errors = [] |
65 |
65 |
66 checkersWithCodes = [ |
66 checkersWithCodes = [ |
67 (self.__checkUnusedArguments, ("U100", "U101")), |
67 (self.__checkUnusedArguments, ("U100", "U101")), |
68 (self.__checkUnusedGlobals, ("U200", )), |
68 (self.__checkUnusedGlobals, ("U200",)), |
69 ] |
69 ] |
70 |
70 |
71 self.__checkers = [] |
71 self.__checkers = [] |
72 for checker, codes in checkersWithCodes: |
72 for checker, codes in checkersWithCodes: |
73 if any(not (code and self.__ignoreCode(code)) for code in codes): |
73 if any(not (code and self.__ignoreCode(code)) for code in codes): |
415 for assignment in self.__tree.body: |
415 for assignment in self.__tree.body: |
416 if isinstance(assignment, ast.Assign): |
416 if isinstance(assignment, ast.Assign): |
417 for target in assignment.targets: |
417 for target in assignment.targets: |
418 if isinstance(target, ast.Name): |
418 if isinstance(target, ast.Name): |
419 variables.add(target.id) |
419 variables.add(target.id) |
420 elif ( |
420 elif isinstance(assignment, ast.AnnAssign) and isinstance( |
421 isinstance(assignment, ast.AnnAssign) |
421 assignment.target, ast.Name |
422 and isinstance(assignment.target, ast.Name) |
|
423 ): |
422 ): |
424 variables.add(assignment.target.id) |
423 variables.add(assignment.target.id) |
425 |
424 |
426 return variables |
425 return variables |
|
426 |
427 |
427 |
428 ####################################################################### |
428 ####################################################################### |
429 ## Class used by 'Unused Arguments' |
429 ## Class used by 'Unused Arguments' |
430 ## |
430 ## |
431 ## adapted from: flake8-unused-arguments v0.0.13 |
431 ## adapted from: flake8-unused-arguments v0.0.13 |
474 for obj in functionNode.body: |
474 for obj in functionNode.body: |
475 self.visit(obj) |
475 self.visit(obj) |
476 |
476 |
477 visit_AsyncFunctionDef = visit_FunctionDef = visit_Lambda = __visitFunctionTypes |
477 visit_AsyncFunctionDef = visit_FunctionDef = visit_Lambda = __visitFunctionTypes |
478 |
478 |
|
479 |
479 ####################################################################### |
480 ####################################################################### |
480 ## Class used by 'Unused Globals' |
481 ## Class used by 'Unused Globals' |
481 ## |
482 ## |
482 ## adapted from: flake8-unused-globals v0.1.9 |
483 ## adapted from: flake8-unused-globals v0.1.9 |
483 ####################################################################### |
484 ####################################################################### |
510 @type ast.Name |
511 @type ast.Name |
511 """ |
512 """ |
512 if isinstance(nameNode.ctx, ast.Load) and nameNode.id in self.__loads: |
513 if isinstance(nameNode.ctx, ast.Load) and nameNode.id in self.__loads: |
513 self.__loads[nameNode.id] += 1 |
514 self.__loads[nameNode.id] += 1 |
514 elif ( |
515 elif ( |
515 isinstance(nameNode.ctx, ast.Store) |
516 isinstance(nameNode.ctx, ast.Store) and nameNode.id not in self.__storeInfo |
516 and nameNode.id not in self.__storeInfo |
|
517 ): |
517 ): |
518 self.__loads[nameNode.id] = 0 |
518 self.__loads[nameNode.id] = 0 |
519 self.__storeInfo[nameNode.id] = GlobalVariableStoreInfo( |
519 self.__storeInfo[nameNode.id] = GlobalVariableStoreInfo( |
520 lineno=nameNode.lineno, offset=nameNode.col_offset |
520 lineno=nameNode.lineno, offset=nameNode.col_offset |
521 ) |
521 ) |