src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py

branch
eric7
changeset 11148
15e30f0c76a8
parent 11147
dee6e106b4d3
child 11150
73d80859079c
equal deleted inserted replaced
11147:dee6e106b4d3 11148:15e30f0c76a8
344 ), 344 ),
345 ), 345 ),
346 (self.__checkDictWithSortedKeys, ("M-251",)), 346 (self.__checkDictWithSortedKeys, ("M-251",)),
347 ( 347 (
348 self.__checkProperties, 348 self.__checkProperties,
349 ("M-260", "M-261", "M-262", "M-263", "M-264", "M-265", "M-266", "M-267"), 349 (
350 "M-260",
351 "M-261",
352 "M-262",
353 "M-263",
354 "M-264",
355 "M-265",
356 "M-266",
357 "M-267",
358 ),
350 ), 359 ),
351 ( 360 (
352 self.__checkDateTime, 361 self.__checkDateTime,
353 ( 362 (
354 "M-301", 363 "M-301",
712 ", ".join(expectedImports), 721 ", ".join(expectedImports),
713 ", ".join(imports), 722 ", ".join(imports),
714 ) 723 )
715 else: 724 else:
716 self.__error( 725 self.__error(
717 node.lineno - 1, node.col_offset, "M-702", ", ".join(expectedImports) 726 node.lineno - 1,
727 node.col_offset,
728 "M-702",
729 ", ".join(expectedImports),
718 ) 730 )
719 731
720 def __checkPep3101(self): 732 def __checkPep3101(self):
721 """ 733 """
722 Private method to check for old style string formatting. 734 Private method to check for old style string formatting.
817 call.lineno - 1, call.col_offset, "M-621", number 829 call.lineno - 1, call.col_offset, "M-621", number
818 ) 830 )
819 831
820 for name in sorted(names): 832 for name in sorted(names):
821 if name not in keywords: 833 if name not in keywords:
822 self.__error(call.lineno - 1, call.col_offset, "M-622", name) 834 self.__error(
835 call.lineno - 1, call.col_offset, "M-622", name
836 )
823 837
824 for arg in range(numArgs): 838 for arg in range(numArgs):
825 if arg not in numbers: 839 if arg not in numbers:
826 self.__error(call.lineno - 1, call.col_offset, "M-631", arg) 840 self.__error(call.lineno - 1, call.col_offset, "M-631", arg)
827 841
1061 ) or ( 1075 ) or (
1062 numPositionalArgs == 0 1076 numPositionalArgs == 0
1063 and numKeywordArgs == 0 1077 and numKeywordArgs == 0
1064 and node.func.id in ("tuple", "list") 1078 and node.func.id in ("tuple", "list")
1065 ): 1079 ):
1066 self.__error(node.lineno - 1, node.col_offset, "M-188", node.func.id) 1080 self.__error(
1081 node.lineno - 1, node.col_offset, "M-188", node.func.id
1082 )
1067 1083
1068 elif ( 1084 elif (
1069 node.func.id in {"list", "reversed"} 1085 node.func.id in {"list", "reversed"}
1070 and numPositionalArgs > 0 1086 and numPositionalArgs > 0
1071 and isinstance(node.args[0], ast.Call) 1087 and isinstance(node.args[0], ast.Call)
1145 and isinstance(node.args[0].slice.step, ast.UnaryOp) 1161 and isinstance(node.args[0].slice.step, ast.UnaryOp)
1146 and isinstance(node.args[0].slice.step.op, ast.USub) 1162 and isinstance(node.args[0].slice.step.op, ast.USub)
1147 and isinstance(node.args[0].slice.step.operand, ast.Constant) 1163 and isinstance(node.args[0].slice.step.operand, ast.Constant)
1148 and node.args[0].slice.step.operand.n == 1 1164 and node.args[0].slice.step.operand.n == 1
1149 ): 1165 ):
1150 self.__error(node.lineno - 1, node.col_offset, "M-195", node.func.id) 1166 self.__error(
1167 node.lineno - 1, node.col_offset, "M-195", node.func.id
1168 )
1151 1169
1152 elif ( 1170 elif (
1153 node.func.id == "map" 1171 node.func.id == "map"
1154 and node not in visitedMapCalls 1172 and node not in visitedMapCalls
1155 and len(node.args) == 2 1173 and len(node.args) == 2
1156 and isinstance(node.args[0], ast.Lambda) 1174 and isinstance(node.args[0], ast.Lambda)
1157 ): 1175 ):
1158 self.__error( 1176 self.__error(
1159 node.lineno - 1, node.col_offset, "M-197", "generator expression" 1177 node.lineno - 1,
1178 node.col_offset,
1179 "M-197",
1180 "generator expression",
1160 ) 1181 )
1161 1182
1162 elif ( 1183 elif (
1163 node.func.id in ("list", "set", "dict") 1184 node.func.id in ("list", "set", "dict")
1164 and len(node.args) == 1 1185 and len(node.args) == 1
1487 ) 1508 )
1488 ) 1509 )
1489 for a, b in pairwise(tokensWithoutWhitespace): 1510 for a, b in pairwise(tokensWithoutWhitespace):
1490 if self.__isImplicitStringConcat(a, b): 1511 if self.__isImplicitStringConcat(a, b):
1491 self.__error( 1512 self.__error(
1492 a.end[0] - 1, a.end[1], "M-851" if a.end[0] == b.start[0] else "M-852" 1513 a.end[0] - 1,
1514 a.end[1],
1515 "M-851" if a.end[0] == b.start[0] else "M-852",
1493 ) 1516 )
1494 1517
1495 def __checkExplicitStringConcat(self): 1518 def __checkExplicitStringConcat(self):
1496 """ 1519 """
1497 Private method to check for explicitly concatenated strings. 1520 Private method to check for explicitly concatenated strings.
2867 Private method to check for inheritance from abstract classes in abc and lack of 2890 Private method to check for inheritance from abstract classes in abc and lack of
2868 any methods decorated with abstract*. 2891 any methods decorated with abstract*.
2869 2892
2870 @param node reference to the node to be processed 2893 @param node reference to the node to be processed
2871 @type ast.ClassDef 2894 @type ast.ClassDef
2872 """ # __IGNORE_WARNING_D234r__ 2895 """ # __IGNORE_WARNING_D-234r__
2873 2896
2874 def isAbcClass(value, name="ABC"): 2897 def isAbcClass(value, name="ABC"):
2875 if isinstance(value, ast.keyword): 2898 if isinstance(value, ast.keyword):
2876 return value.arg == "metaclass" and isAbcClass(value.value, "ABCMeta") 2899 return value.arg == "metaclass" and isAbcClass(value.value, "ABCMeta")
2877 2900
3190 """ 3213 """
3191 Private method to check the usage of exceptions with added note. 3214 Private method to check the usage of exceptions with added note.
3192 3215
3193 @param node reference to the node to be processed 3216 @param node reference to the node to be processed
3194 @type ast.expr or None 3217 @type ast.expr or None
3195 """ # noqa: D234y 3218 """ # noqa: D-234y
3196 3219
3197 def superwalk(node: ast.AST | list[ast.AST]): 3220 def superwalk(node: ast.AST | list[ast.AST]):
3198 """ 3221 """
3199 Function to walk an AST node or a list of AST nodes. 3222 Function to walk an AST node or a list of AST nodes.
3200 3223
3221 """ 3244 """
3222 Private method to check for duplicate key value pairs in a dictionary literal. 3245 Private method to check for duplicate key value pairs in a dictionary literal.
3223 3246
3224 @param node reference to the node to be processed 3247 @param node reference to the node to be processed
3225 @type ast.Dict 3248 @type ast.Dict
3226 """ # noqa: D234r 3249 """ # noqa: D-234r
3227 3250
3228 def convertToValue(item): 3251 def convertToValue(item):
3229 """ 3252 """
3230 Function to extract the value of a given item. 3253 Function to extract the value of a given item.
3231 3254
4549 4572
4550 return case.body[-1] 4573 return case.body[-1]
4551 4574
4552 4575
4553 # 4576 #
4554 # eflag: noqa = M891 4577 # eflag: noqa = M-891

eric ide

mercurial