Sun, 21 May 2023 16:04:59 +0200
Code Style Checker
- Updated the simplify checker to support more cases.
--- a/src/eric7/Documentation/Help/source.qhp Sun May 21 15:26:11 2023 +0200 +++ b/src/eric7/Documentation/Help/source.qhp Sun May 21 16:04:59 2023 +0200 @@ -14960,6 +14960,7 @@ <keyword name="SimplifyNodeVisitor.__check906" id="SimplifyNodeVisitor.__check906" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html#SimplifyNodeVisitor.__check906" /> <keyword name="SimplifyNodeVisitor.__check907" id="SimplifyNodeVisitor.__check907" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html#SimplifyNodeVisitor.__check907" /> <keyword name="SimplifyNodeVisitor.__check909" id="SimplifyNodeVisitor.__check909" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html#SimplifyNodeVisitor.__check909" /> + <keyword name="SimplifyNodeVisitor.__check910" id="SimplifyNodeVisitor.__check910" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html#SimplifyNodeVisitor.__check910" /> <keyword name="SimplifyNodeVisitor.__expressionUsesVariable" id="SimplifyNodeVisitor.__expressionUsesVariable" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html#SimplifyNodeVisitor.__expressionUsesVariable" /> <keyword name="SimplifyNodeVisitor.__getDuplicatedIsinstanceCall" id="SimplifyNodeVisitor.__getDuplicatedIsinstanceCall" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html#SimplifyNodeVisitor.__getDuplicatedIsinstanceCall" /> <keyword name="SimplifyNodeVisitor.__getIfBodyPairs" id="SimplifyNodeVisitor.__getIfBodyPairs" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html#SimplifyNodeVisitor.__getIfBodyPairs" />
--- a/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html Sun May 21 15:26:11 2023 +0200 +++ b/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html Sun May 21 16:04:59 2023 +0200 @@ -252,6 +252,10 @@ <td>Private method to check for reflexive assignments.</td> </tr> <tr> +<td><a href="#SimplifyNodeVisitor.__check910">__check910</a></td> +<td>Private method to check for uses of 'dict.get(key, None)'.</td> +</tr> +<tr> <td><a href="#SimplifyNodeVisitor.__expressionUsesVariable">__expressionUsesVariable</a></td> <td>Private method to check, if a variable is used by an expression.</td> </tr> @@ -1069,6 +1073,20 @@ reference to the AST node to be checked </dd> </dl> +<a NAME="SimplifyNodeVisitor.__check910" ID="SimplifyNodeVisitor.__check910"></a> +<h4>SimplifyNodeVisitor.__check910</h4> +<b>__check910</b>(<i>node</i>) + +<p> + Private method to check for uses of 'dict.get(key, None)'. +</p> +<dl> + +<dt><i>node</i> (ast.Call)</dt> +<dd> +reference to the AST node to be checked +</dd> +</dl> <a NAME="SimplifyNodeVisitor.__expressionUsesVariable" ID="SimplifyNodeVisitor.__expressionUsesVariable"></a> <h4>SimplifyNodeVisitor.__expressionUsesVariable</h4> <b>__expressionUsesVariable</b>(<i>expr, var</i>)
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py Sun May 21 15:26:11 2023 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyChecker.py Sun May 21 16:04:59 2023 +0200 @@ -74,6 +74,7 @@ "Y906", "Y907", "Y909", + "Y910", ] def __init__(self, source, filename, tree, selected, ignored, expected, repeat):
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyNodeVisitor.py Sun May 21 15:26:11 2023 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyNodeVisitor.py Sun May 21 16:04:59 2023 +0200 @@ -20,7 +20,7 @@ from .ast_unparse import unparse ############################################################################### -## The following code is derived from the flake8-simplify package (v0.19.3). +## The following code is derived from the flake8-simplify package (v0.20.0). ## ## Original License: ## @@ -182,6 +182,7 @@ self.__check901(node) self.__check905(node) self.__check906(node) + self.__check910(node) self.generic_visit(node) @@ -1891,6 +1892,34 @@ srccode = unparse(node) self.__error(node.lineno - 1, node.col_offset, "Y909", srccode) + def __check910(self, node): + """ + Private method to check for uses of 'dict.get(key, None)'. + + @param node reference to the AST node to be checked + @type ast.Call + """ + errors = [] + if not ( + isinstance(node.func, ast.Attribute) + and node.func.attr == "get" + and isinstance(node.func.ctx, ast.Load) + ): + return errors + + # check the argument value + if not ( + len(node.args) == 2 + and isinstance(node.args[1], BOOL_CONST_TYPES) + and node.args[1].value is None + ): + return errors + + actual = unparse(node) + func = unparse(node.func) + key = unparse(node.args[0]) + expected = f"{func}({key})" + self.__error(node.lineno - 1, node.col_offset, "Y910", expected, actual) # # eflag: noqa = M891
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/translations.py Sun May 21 15:26:11 2023 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/translations.py Sun May 21 16:04:59 2023 +0200 @@ -172,6 +172,9 @@ "Y909": QCoreApplication.translate( "SimplifyChecker", '''Remove reflexive assignment "{0}"''' ), + "Y910": QCoreApplication.translate( + "SimplifyChecker", '''Use "{0}" instead of "{1}"''' + ), } _simplifyMessagesSampleArgs = {