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

branch
eric7
changeset 10050
3750abc45d5e
parent 10047
cc9ead6d1c46
child 10116
4a619fb7bd09
equal deleted inserted replaced
10049:61a1757626ac 10050:3750abc45d5e
1897 Private method to check for uses of 'dict.get(key, None)'. 1897 Private method to check for uses of 'dict.get(key, None)'.
1898 1898
1899 @param node reference to the AST node to be checked 1899 @param node reference to the AST node to be checked
1900 @type ast.Call 1900 @type ast.Call
1901 """ 1901 """
1902 errors = []
1903 if not ( 1902 if not (
1904 isinstance(node.func, ast.Attribute) 1903 isinstance(node.func, ast.Attribute)
1905 and node.func.attr == "get" 1904 and node.func.attr == "get"
1906 and isinstance(node.func.ctx, ast.Load) 1905 and isinstance(node.func.ctx, ast.Load)
1907 ): 1906 ):
1908 return errors 1907 return
1909 1908
1910 # check the argument value 1909 # check the argument value
1911 if not ( 1910 if not (
1912 len(node.args) == 2 1911 len(node.args) == 2
1913 and isinstance(node.args[1], BOOL_CONST_TYPES) 1912 and isinstance(node.args[1], BOOL_CONST_TYPES)
1914 and node.args[1].value is None 1913 and node.args[1].value is None
1915 ): 1914 ):
1916 return errors 1915 return
1917 1916
1918 actual = unparse(node) 1917 actual = unparse(node)
1919 func = unparse(node.func) 1918 func = unparse(node.func)
1920 key = unparse(node.args[0]) 1919 key = unparse(node.args[0])
1921 expected = f"{func}({key})" 1920 expected = f"{func}({key})"
1922 self.__error(node.lineno - 1, node.col_offset, "Y910", expected, actual) 1921 self.__error(node.lineno - 1, node.col_offset, "Y910", expected, actual)
1923 1922
1923
1924 # 1924 #
1925 # eflag: noqa = M891 1925 # eflag: noqa = M891

eric ide

mercurial