113 "CodingChecker": 'latin-1, utf-8', |
113 "CodingChecker": 'latin-1, utf-8', |
114 "CopyrightChecker": { |
114 "CopyrightChecker": { |
115 "MinFilesize": 0, |
115 "MinFilesize": 0, |
116 "Author": "", |
116 "Author": "", |
117 }, |
117 }, |
|
118 "BuiltinsChecker": { |
|
119 "str": ["unicode", ], |
|
120 "chr": ["unichr", ], |
|
121 } |
118 } |
122 } |
119 |
123 |
120 self.__checkers = [] |
124 self.__checkers = [] |
121 for checker, codes in checkersWithCodes: |
125 for checker, codes in checkersWithCodes: |
122 if any(not (code and self.__ignoreCode(code)) |
126 if any(not (code and self.__ignoreCode(code)) |
489 |
493 |
490 def __checkBuiltins(self): |
494 def __checkBuiltins(self): |
491 """ |
495 """ |
492 Private method to check, if built-ins are shadowed. |
496 Private method to check, if built-ins are shadowed. |
493 """ |
497 """ |
|
498 ignoreBuiltinAssignments = self.__args.get( |
|
499 "BuiltinsChecker", self.__defaultArgs["BuiltinsChecker"]) |
|
500 |
494 for node in ast.walk(self.__tree): |
501 for node in ast.walk(self.__tree): |
495 if isinstance(node, ast.Assign): |
502 if isinstance(node, ast.Assign): |
496 # assign statement |
503 # assign statement |
497 for element in node.targets: |
504 for element in node.targets: |
498 if isinstance(element, ast.Name) and \ |
505 if isinstance(element, ast.Name) and \ |
499 element.id in self.__builtins: |
506 element.id in self.__builtins: |
500 value = node.value |
507 value = node.value |
501 if isinstance(value, ast.Name) and \ |
508 if isinstance(value, ast.Name) and \ |
502 value.id in ["unicode", "unichr"]: |
509 element.id in ignoreBuiltinAssignments and \ |
|
510 value.id in ignoreBuiltinAssignments[element.id]: |
503 # ignore compatibility assignments |
511 # ignore compatibility assignments |
504 # TODO: make this configurable |
|
505 continue |
512 continue |
506 self.__error(element.lineno - 1, element.col_offset, |
513 self.__error(element.lineno - 1, element.col_offset, |
507 "M131", element.id) |
514 "M131", element.id) |
508 elif isinstance(element, (ast.Tuple, ast.List)): |
515 elif isinstance(element, (ast.Tuple, ast.List)): |
509 for tupleElement in element.elts: |
516 for tupleElement in element.elts: |