556 |
556 |
557 keywords = {keyword.arg for keyword in call.keywords} |
557 keywords = {keyword.arg for keyword in call.keywords} |
558 numArgs = len(call.args) |
558 numArgs = len(call.args) |
559 if strArgs: |
559 if strArgs: |
560 numArgs -= 1 |
560 numArgs -= 1 |
561 if sys.version_info < (3, 5): |
561 hasKwArgs = any(kw.arg is None for kw in call.keywords) |
562 hasKwArgs = bool(call.kwargs) |
562 hasStarArgs = sum(1 for arg in call.args |
563 hasStarArgs = bool(call.starargs) |
563 if isinstance(arg, ast.Starred)) |
564 else: |
564 |
565 hasKwArgs = any(kw.arg is None for kw in call.keywords) |
565 if hasKwArgs: |
566 hasStarArgs = sum(1 for arg in call.args |
566 keywords.discard(None) |
567 if isinstance(arg, ast.Starred)) |
567 if hasStarArgs: |
568 |
568 numArgs -= 1 |
569 if hasKwArgs: |
|
570 keywords.discard(None) |
|
571 if hasStarArgs: |
|
572 numArgs -= 1 |
|
573 |
569 |
574 # if starargs or kwargs is not None, it can't count the |
570 # if starargs or kwargs is not None, it can't count the |
575 # parameters but at least check if the args are used |
571 # parameters but at least check if the args are used |
576 if hasKwArgs: |
572 if hasKwArgs: |
577 if not names: |
573 if not names: |
1292 Public method to handle f-string arguments. |
1288 Public method to handle f-string arguments. |
1293 |
1289 |
1294 @param node reference to the node to be processed |
1290 @param node reference to the node to be processed |
1295 @type ast.JoinedStr |
1291 @type ast.JoinedStr |
1296 """ |
1292 """ |
1297 if sys.version_info >= (3, 6): |
1293 if self.__withinLoggingStatement(): |
1298 if self.__withinLoggingStatement(): |
1294 if any(isinstance(i, ast.FormattedValue) for i in node.values): |
1299 if any(isinstance(i, ast.FormattedValue) for i in node.values): |
1295 if self.__withinLoggingArgument(): |
1300 if self.__withinLoggingArgument(): |
1296 self.violations.append((node, "M654")) |
1301 self.violations.append((node, "M654")) |
1297 |
1302 |
1298 super(LoggingVisitor, self).generic_visit(node) |
1303 super(LoggingVisitor, self).generic_visit(node) |
|
1304 |
1299 |
1305 |
1300 |
1306 class BugBearVisitor(ast.NodeVisitor): |
1301 class BugBearVisitor(ast.NodeVisitor): |
1307 """ |
1302 """ |
1308 Class implementing a node visitor to check for various topics. |
1303 Class implementing a node visitor to check for various topics. |
1502 Public method to handle f-string arguments. |
1497 Public method to handle f-string arguments. |
1503 |
1498 |
1504 @param node reference to the node to be processed |
1499 @param node reference to the node to be processed |
1505 @type ast.JoinedStr |
1500 @type ast.JoinedStr |
1506 """ |
1501 """ |
1507 if sys.version_info >= (3, 6): |
1502 for value in node.values: |
1508 for value in node.values: |
1503 if isinstance(value, ast.FormattedValue): |
1509 if isinstance(value, ast.FormattedValue): |
1504 return |
1510 return |
1505 |
1511 |
1506 self.violations.append((node, "M508")) |
1512 self.violations.append((node, "M508")) |
|
1513 |
1507 |
1514 def __checkForM502(self, node): |
1508 def __checkForM502(self, node): |
1515 """ |
1509 """ |
1516 Private method to check the use of *strip(). |
1510 Private method to check the use of *strip(). |
1517 |
1511 |