609 def __checkBuiltins(self): |
610 def __checkBuiltins(self): |
610 """ |
611 """ |
611 Private method to check, if built-ins are shadowed. |
612 Private method to check, if built-ins are shadowed. |
612 """ |
613 """ |
613 functionDefs = [ast.FunctionDef] |
614 functionDefs = [ast.FunctionDef] |
614 try: |
615 with contextlib.suppress(AttributeError): |
615 functionDefs.append(ast.AsyncFunctionDef) |
616 functionDefs.append(ast.AsyncFunctionDef) |
616 except AttributeError: |
|
617 pass |
|
618 |
617 |
619 ignoreBuiltinAssignments = self.__args.get( |
618 ignoreBuiltinAssignments = self.__args.get( |
620 "BuiltinsChecker", |
619 "BuiltinsChecker", |
621 MiscellaneousCheckerDefaultArgs["BuiltinsChecker"]) |
620 MiscellaneousCheckerDefaultArgs["BuiltinsChecker"]) |
622 |
621 |
797 immutableCalls = ( |
796 immutableCalls = ( |
798 "tuple", |
797 "tuple", |
799 "frozenset", |
798 "frozenset", |
800 ) |
799 ) |
801 functionDefs = [ast.FunctionDef] |
800 functionDefs = [ast.FunctionDef] |
802 try: |
801 with contextlib.suppress(AttributeError): |
803 functionDefs.append(ast.AsyncFunctionDef) |
802 functionDefs.append(ast.AsyncFunctionDef) |
804 except AttributeError: |
|
805 pass |
|
806 |
803 |
807 for node in ast.walk(self.__tree): |
804 for node in ast.walk(self.__tree): |
808 if any(isinstance(node, functionDef) |
805 if any(isinstance(node, functionDef) |
809 for functionDef in functionDefs): |
806 for functionDef in functionDefs): |
810 defaults = node.args.defaults[:] |
807 defaults = node.args.defaults[:] |
811 try: |
808 with contextlib.suppress(AttributeError): |
812 defaults += node.args.kw_defaults[:] |
809 defaults += node.args.kw_defaults[:] |
813 except AttributeError: |
|
814 pass |
|
815 for default in defaults: |
810 for default in defaults: |
816 if any(isinstance(default, mutableType) |
811 if any(isinstance(default, mutableType) |
817 for mutableType in mutableTypes): |
812 for mutableType in mutableTypes): |
818 typeName = type(default).__name__ |
813 typeName = type(default).__name__ |
819 if isinstance(default, ast.Call): |
814 if isinstance(default, ast.Call): |
1159 @param node reference to the node to be processed |
1154 @param node reference to the node to be processed |
1160 @type ast.Call |
1155 @type ast.Call |
1161 @return logging level |
1156 @return logging level |
1162 @rtype str or None |
1157 @rtype str or None |
1163 """ |
1158 """ |
1164 try: |
1159 with contextlib.suppress(AttributeError): |
1165 if node.func.value.id == "warnings": |
1160 if node.func.value.id == "warnings": |
1166 return None |
1161 return None |
1167 |
1162 |
1168 if node.func.attr in LoggingVisitor.LoggingLevels: |
1163 if node.func.attr in LoggingVisitor.LoggingLevels: |
1169 return node.func.attr |
1164 return node.func.attr |
1170 except AttributeError: |
|
1171 pass |
|
1172 |
1165 |
1173 return None |
1166 return None |
1174 |
1167 |
1175 def __isFormatCall(self, node): |
1168 def __isFormatCall(self, node): |
1176 """ |
1169 """ |
1379 node.func.id == "setattr" and |
1372 node.func.id == "setattr" and |
1380 len(node.args) == 3 and |
1373 len(node.args) == 3 and |
1381 AstUtilities.isString(node.args[1]) |
1374 AstUtilities.isString(node.args[1]) |
1382 ): |
1375 ): |
1383 self.violations.append((node, "M513")) |
1376 self.violations.append((node, "M513")) |
1384 except (AttributeError, IndexError): |
|
1385 pass |
|
1386 |
1377 |
1387 self.generic_visit(node) |
1378 self.generic_visit(node) |
1388 |
1379 |
1389 def visit_Attribute(self, node): |
1380 def visit_Attribute(self, node): |
1390 """ |
1381 """ |