73 |
73 |
74 @param node reference to the Expr node |
74 @param node reference to the Expr node |
75 @type ast.Expr |
75 @type ast.Expr |
76 """ |
76 """ |
77 self.__check112(node) |
77 self.__check112(node) |
|
78 |
|
79 self.generic_visit(node) |
|
80 |
|
81 def visit_Assign(self, node): |
|
82 """ |
|
83 Public method to process an Assign node. |
|
84 |
|
85 @param node reference to the Assign node |
|
86 @type ast.Assign |
|
87 """ |
|
88 self.__check121(node) |
78 |
89 |
79 self.generic_visit(node) |
90 self.generic_visit(node) |
80 |
91 |
81 def visit_BoolOp(self, node): |
92 def visit_BoolOp(self, node): |
82 """ |
93 """ |
1055 node.bases[0].id == "object" |
1066 node.bases[0].id == "object" |
1056 ): |
1067 ): |
1057 self.__error(node.lineno - 1, node.col_offset, "Y120", |
1068 self.__error(node.lineno - 1, node.col_offset, "Y120", |
1058 node.name) |
1069 node.name) |
1059 |
1070 |
|
1071 def __check121(self, node): |
|
1072 """ |
|
1073 Private method to check for assignments that could be converted into |
|
1074 an augmented assignment |
|
1075 |
|
1076 @param node reference to the AST node to be checked |
|
1077 @type ast.Assign |
|
1078 """ |
|
1079 # a = a - b |
|
1080 if ( |
|
1081 len(node.targets) == 1 and |
|
1082 isinstance(node.targets[0], ast.Name) and |
|
1083 isinstance(node.value, ast.BinOp) and |
|
1084 isinstance(node.value.left, ast.Name) and |
|
1085 node.value.left.id == node.targets[0].id and |
|
1086 not isinstance(node.value.right, ast.Tuple) |
|
1087 ): |
|
1088 newNode = ast.AugAssign(node.targets[0], node.value.op, |
|
1089 node.value.right) |
|
1090 self.__error(node.lineno - 1, node.col_offset, "Y121", |
|
1091 unparse(newNode), unparse(node)) |
|
1092 |
1060 def __check201(self, node): |
1093 def __check201(self, node): |
1061 """ |
1094 """ |
1062 Private method to check for calls where an unary 'not' is used for |
1095 Private method to check for calls where an unary 'not' is used for |
1063 an unequality. |
1096 an unequality. |
1064 |
1097 |