diff -r 29e896e9e74e -r 91c3ba0767ad src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py --- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Fri Sep 01 15:54:43 2023 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Fri Sep 01 16:54:26 2023 +0200 @@ -142,6 +142,7 @@ "M531", "M532", "M533", + "M534", ## Bugbear++ "M581", "M582", @@ -337,6 +338,7 @@ "M531", "M532", "M533", + "M534", "M581", "M582", ), @@ -1615,7 +1617,7 @@ ####################################################################### ## BugBearVisitor ## -## adapted from: flake8-bugbear v22.12.6 +## adapted from: flake8-bugbear v23.7.10 ## ## Original: Copyright (c) 2016 Ćukasz Langa ####################################################################### @@ -2025,6 +2027,7 @@ self.__checkForM526(node) self.__checkForM528(node) + self.__checkForM534(node) self.generic_visit(node) @@ -2296,11 +2299,11 @@ if len(node.args) != 1 or not AstUtilities.isString(node.args[0]): return # used arguments don't match the builtin strip - s = AstUtilities.getValue(node.args[0]) - if len(s) == 1: + value = AstUtilities.getValue(node.args[0]) + if len(value) == 1: return # stripping just one character - if len(s) == len(set(s)): + if len(value) == len(set(value)): return # no characters appear more than once self.violations.append((node, "M505")) @@ -2812,12 +2815,36 @@ @param node reference to the node to be processed @type ast.Set """ - constants = [ - item.value - for item in filter(lambda x: isinstance(x, ast.Constant), node.elts) - ] - if len(constants) != len(set(constants)): - self.violations.append((node, "M533")) + seen = set() + for elt in node.elts: + if not isinstance(elt, ast.Constant): + continue + if elt.value in seen: + self.violations.append((node, "M533", repr(elt.value))) + else: + seen.add(elt.value) + + def __checkForM534(self, node): + """ + Private method to check that re.sub/subn/split arguments flags/count/maxsplit + are passed as keyword arguments. + + @param node reference to the node to be processed + @type ast.Call + """ + if not isinstance(node.func, ast.Attribute): + return + if not isinstance(node.func.value, ast.Name) or node.func.value.id != "re": + return + + def check(numArgs, paramName): + if len(node.args) > numArgs: + self.violations.append((node, "M534", node.func.attr, paramName)) + + if node.func.attr in ("sub", "subn"): + check(3, "count") + elif node.func.attr == "split": + check(2, "maxsplit") class NameFinder(ast.NodeVisitor):