src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyNodeVisitor.py

branch
eric7
changeset 10047
cc9ead6d1c46
parent 9786
f94b530722af
child 10050
3750abc45d5e
diff -r 35b27af462ef -r cc9ead6d1c46 src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/SimplifyNodeVisitor.py
--- 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

eric ide

mercurial