541 if hasStarArgs: |
541 if hasStarArgs: |
542 numArgs -= 1 |
542 numArgs -= 1 |
543 |
543 |
544 # if starargs or kwargs is not None, it can't count the |
544 # if starargs or kwargs is not None, it can't count the |
545 # parameters but at least check if the args are used |
545 # parameters but at least check if the args are used |
546 if hasKwArgs: |
546 if hasKwArgs and not names: |
547 if not names: |
547 # No names but kwargs |
548 # No names but kwargs |
548 self.__error(call.lineno - 1, call.col_offset, "M623") |
549 self.__error(call.lineno - 1, call.col_offset, "M623") |
549 if hasStarArgs and not numbers: |
550 if hasStarArgs: |
550 # No numbers but args |
551 if not numbers: |
551 self.__error(call.lineno - 1, call.col_offset, "M624") |
552 # No numbers but args |
|
553 self.__error(call.lineno - 1, call.col_offset, "M624") |
|
554 |
552 |
555 if not hasKwArgs and not hasStarArgs: |
553 if not hasKwArgs and not hasStarArgs: |
556 # can actually verify numbers and names |
554 # can actually verify numbers and names |
557 for number in sorted(numbers): |
555 for number in sorted(numbers): |
558 if number >= numArgs: |
556 if number >= numArgs: |
1197 |
1195 |
1198 @param node reference to the node to be processed |
1196 @param node reference to the node to be processed |
1199 @type ast.Call |
1197 @type ast.Call |
1200 """ |
1198 """ |
1201 # we are in a logging statement |
1199 # we are in a logging statement |
1202 if self.__withinLoggingStatement(): |
1200 if ( |
1203 if self.__withinLoggingArgument() and self.__isFormatCall(node): |
1201 self.__withinLoggingStatement() and |
1204 self.violations.append((node, "M651")) |
1202 self.__withinLoggingArgument() and |
1205 super().generic_visit(node) |
1203 self.__isFormatCall(node) |
1206 return |
1204 ): |
|
1205 self.violations.append((node, "M651")) |
|
1206 super().generic_visit(node) |
|
1207 return |
1207 |
1208 |
1208 loggingLevel = self.__detectLoggingLevel(node) |
1209 loggingLevel = self.__detectLoggingLevel(node) |
1209 |
1210 |
1210 if loggingLevel and self.__currentLoggingLevel is None: |
1211 if loggingLevel and self.__currentLoggingLevel is None: |
1211 self.__currentLoggingLevel = loggingLevel |
1212 self.__currentLoggingLevel = loggingLevel |
1263 Public method to handle f-string arguments. |
1264 Public method to handle f-string arguments. |
1264 |
1265 |
1265 @param node reference to the node to be processed |
1266 @param node reference to the node to be processed |
1266 @type ast.JoinedStr |
1267 @type ast.JoinedStr |
1267 """ |
1268 """ |
1268 if self.__withinLoggingStatement(): |
1269 if ( |
1269 if any(isinstance(i, ast.FormattedValue) for i in node.values): |
1270 self.__withinLoggingStatement() and |
1270 if self.__withinLoggingArgument(): |
1271 any(isinstance(i, ast.FormattedValue) for i in node.values) and |
1271 self.violations.append((node, "M654")) |
1272 self.__withinLoggingArgument() |
1272 |
1273 ): |
1273 super().generic_visit(node) |
1274 self.violations.append((node, "M654")) |
|
1275 |
|
1276 super().generic_visit(node) |
1274 |
1277 |
1275 |
1278 |
1276 class BugBearVisitor(ast.NodeVisitor): |
1279 class BugBearVisitor(ast.NodeVisitor): |
1277 """ |
1280 """ |
1278 Class implementing a node visitor to check for various topics. |
1281 Class implementing a node visitor to check for various topics. |
1421 |
1424 |
1422 elif len(node.targets) == 1: |
1425 elif len(node.targets) == 1: |
1423 target = node.targets[0] |
1426 target = node.targets[0] |
1424 if ( |
1427 if ( |
1425 isinstance(target, ast.Attribute) and |
1428 isinstance(target, ast.Attribute) and |
1426 isinstance(target.value, ast.Name) |
1429 isinstance(target.value, ast.Name) and |
|
1430 (target.value.id, target.attr) == ('os', 'environ') |
1427 ): |
1431 ): |
1428 if (target.value.id, target.attr) == ('os', 'environ'): |
1432 self.violations.append((node, "M506")) |
1429 self.violations.append((node, "M506")) |
|
1430 |
1433 |
1431 self.generic_visit(node) |
1434 self.generic_visit(node) |
1432 |
1435 |
1433 def visit_For(self, node): |
1436 def visit_For(self, node): |
1434 """ |
1437 """ |