--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Fri Aug 02 19:24:32 2024 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Sat Aug 03 11:01:25 2024 +0200 @@ -96,17 +96,18 @@ "M197", "M198", "M199", + "M200", ## Dictionaries with sorted keys - "M201", + "M251", ## Property - "M210", - "M211", - "M212", - "M213", - "M214", - "M215", - "M216", - "M217", + "M260", + "M261", + "M262", + "M263", + "M264", + "M265", + "M266", + "M267", ## Naive datetime usage "M301", "M302", @@ -301,12 +302,13 @@ "M197", "M198", "M199", + "M200", ), ), - (self.__checkDictWithSortedKeys, ("M201",)), + (self.__checkDictWithSortedKeys, ("M251",)), ( self.__checkProperties, - ("M210", "M211", "M212", "M213", "M214", "M215", "M216", "M217"), + ("M260", "M261", "M262", "M263", "M264", "M265", "M266", "M267"), ), ( self.__checkDateTime, @@ -887,9 +889,15 @@ """ Private method to check some comprehension related things. - This method is adapted from: flake8-comprehensions v3.14.0 + This method is adapted from: flake8-comprehensions v3.15.0 Original: Copyright (c) 2017 Adam Johnson """ + compType = { + ast.DictComp: "dict", + ast.ListComp: "list", + ast.SetComp: "set", + } + visitedMapCalls = set() for node in ast.walk(self.__tree): @@ -1136,37 +1144,47 @@ node.lineno - 1, node.col_offset, "M197", comprehensionType ) - elif isinstance(node, (ast.DictComp, ast.ListComp, ast.SetComp)) and ( - len(node.generators) == 1 - and not node.generators[0].ifs - and not node.generators[0].is_async - and ( - ( - isinstance(node, (ast.ListComp, ast.SetComp)) - and isinstance(node.elt, ast.Name) - and isinstance(node.generators[0].target, ast.Name) - and node.elt.id == node.generators[0].target.id - ) - or ( - isinstance(node, ast.DictComp) - and isinstance(node.key, ast.Name) - and isinstance(node.value, ast.Name) - and isinstance(node.generators[0].target, ast.Tuple) - and len(node.generators[0].target.elts) == 2 - and isinstance(node.generators[0].target.elts[0], ast.Name) - and node.generators[0].target.elts[0].id == node.key.id - and isinstance(node.generators[0].target.elts[1], ast.Name) - and node.generators[0].target.elts[1].id == node.value.id - ) + elif isinstance(node, (ast.DictComp, ast.ListComp, ast.SetComp)) and ( + len(node.generators) == 1 + and not node.generators[0].ifs + and not node.generators[0].is_async + ): + if ( + isinstance(node, (ast.ListComp, ast.SetComp)) + and isinstance(node.elt, ast.Name) + and isinstance(node.generators[0].target, ast.Name) + and node.elt.id == node.generators[0].target.id + ) or ( + isinstance(node, ast.DictComp) + and isinstance(node.key, ast.Name) + and isinstance(node.value, ast.Name) + and isinstance(node.generators[0].target, ast.Tuple) + and len(node.generators[0].target.elts) == 2 + and isinstance(node.generators[0].target.elts[0], ast.Name) + and node.generators[0].target.elts[0].id == node.key.id + and isinstance(node.generators[0].target.elts[1], ast.Name) + and node.generators[0].target.elts[1].id == node.value.id + ): + self.__error( + node.lineno - 1, + node.col_offset, + "M196", + compType[node.__class__], ) + + elif ( + isinstance(node, ast.DictComp) + and isinstance(node.key, ast.Name) + and isinstance(node.value, ast.Constant) + and isinstance(node.generators[0].target, ast.Name) + and node.key.id == node.generators[0].target.id ): - compType = { - ast.DictComp: "dict", - ast.ListComp: "list", - ast.SetComp: "set", - }[node.__class__] - - self.__error(node.lineno - 1, node.col_offset, "M196", compType) + self.__error( + node.lineno - 1, + node.col_offset, + "M200", + compType[node.__class__], + ) def __checkMutableDefault(self): """ @@ -1256,7 +1274,7 @@ if ( "__IGNORE_WARNING__" in self.__source[node.lineno - 1] - or "__IGNORE_WARNING_M201__" in self.__source[node.lineno - 1] + or "__IGNORE_WARNING_M251__" in self.__source[node.lineno - 1] ): return False @@ -1274,7 +1292,7 @@ self.__error( key2.lineno - 1, key2.col_offset, - "M201", + "M251", key2.value, key1.value, ) @@ -1364,7 +1382,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M210", + "M260", len(node.args.args), ) @@ -1377,7 +1395,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M215", + "M265", node.name, decorator.value.id, ) @@ -1385,7 +1403,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M213", + "M263", decorator.value.id, node.name, ) @@ -1393,7 +1411,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M211", + "M261", len(node.args.args), ) @@ -1405,7 +1423,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M216", + "M266", node.name, decorator.value.id, ) @@ -1413,7 +1431,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M214", + "M264", decorator.value.id, node.name, ) @@ -1421,12 +1439,12 @@ self.__error( node.lineno - 1, node.col_offset, - "M212", + "M262", len(node.args.args), ) if propertyCount > 1: - self.__error(node.lineno - 1, node.col_offset, "M217", node.name) + self.__error(node.lineno - 1, node.col_offset, "M267", node.name) ####################################################################### ## The following methods check for implicitly concatenated strings.