1352 Public method to handle constant nodes. |
1352 Public method to handle constant nodes. |
1353 |
1353 |
1354 @param node reference to the bytes node |
1354 @param node reference to the bytes node |
1355 @type ast.Constant |
1355 @type ast.Constant |
1356 """ |
1356 """ |
1357 if sys.version_info >= (3, 8, 0): |
1357 if AstUtilities.isBaseString(node): |
1358 if AstUtilities.isBaseString(node): |
1358 self.__addNode(node) |
1359 self.__addNode(node) |
|
1360 else: |
|
1361 super().generic_visit(node) |
|
1362 else: |
1359 else: |
1363 super().generic_visit(node) |
1360 super().generic_visit(node) |
1364 |
1361 |
1365 def __visitDefinition(self, node): |
1362 def __visitDefinition(self, node): |
1366 """ |
1363 """ |
2427 for subnode in node.body: |
2424 for subnode in node.body: |
2428 if not isinstance(subnode, ast.Expr): |
2425 if not isinstance(subnode, ast.Expr): |
2429 continue |
2426 continue |
2430 |
2427 |
2431 if ( |
2428 if ( |
2432 sys.version_info < (3, 8, 0) |
2429 isinstance( |
2433 and isinstance( |
|
2434 subnode.value, |
2430 subnode.value, |
2435 (ast.Num, ast.Bytes, ast.NameConstant, ast.List, ast.Set, ast.Dict), |
2431 (ast.List, ast.Set, ast.Dict), |
2436 ) |
2432 ) |
2437 ) or ( |
2433 or ( |
2438 sys.version_info >= (3, 8, 0) |
2434 isinstance(subnode.value, ast.Constant) |
2439 and ( |
2435 and ( |
2440 isinstance( |
2436 isinstance( |
2441 subnode.value, |
2437 subnode.value.value, |
2442 (ast.List, ast.Set, ast.Dict), |
2438 (int, float, complex, bytes, bool), |
2443 ) |
|
2444 or ( |
|
2445 isinstance(subnode.value, ast.Constant) |
|
2446 and ( |
|
2447 isinstance( |
|
2448 subnode.value.value, |
|
2449 (int, float, complex, bytes, bool), |
|
2450 ) |
|
2451 or subnode.value.value is None |
|
2452 ) |
2439 ) |
|
2440 or subnode.value.value is None |
2453 ) |
2441 ) |
2454 ) |
2442 ) |
2455 ): |
2443 ): |
2456 self.violations.append((subnode, "M518")) |
2444 self.violations.append((subnode, "M518")) |
2457 |
2445 |