179 self.__check402(node) |
179 self.__check402(node) |
180 self.__check901(node) |
180 self.__check901(node) |
181 self.__check905(node) |
181 self.__check905(node) |
182 self.__check906(node) |
182 self.__check906(node) |
183 self.__check910(node) |
183 self.__check910(node) |
|
184 self.__check911(node) |
184 |
185 |
185 self.generic_visit(node) |
186 self.generic_visit(node) |
186 |
187 |
187 def visit_With(self, node): |
188 def visit_With(self, node): |
188 """ |
189 """ |
1898 func = unparse(node.func) |
1899 func = unparse(node.func) |
1899 key = unparse(node.args[0]) |
1900 key = unparse(node.args[0]) |
1900 expected = f"{func}({key})" |
1901 expected = f"{func}({key})" |
1901 self.__error(node.lineno - 1, node.col_offset, "Y910", expected, actual) |
1902 self.__error(node.lineno - 1, node.col_offset, "Y910", expected, actual) |
1902 |
1903 |
|
1904 def __check911(self, node): |
|
1905 """ |
|
1906 Private method to check for the expression "zip(_.keys(), _.values())". |
|
1907 |
|
1908 @param node reference to the AST node to be checked |
|
1909 @type ast.Call |
|
1910 """ |
|
1911 if isinstance(node, ast.Call) and ( |
|
1912 isinstance(node.func, ast.Name) |
|
1913 and node.func.id == "zip" |
|
1914 and len(node.args) == 2 |
|
1915 ): |
|
1916 firstArg, secondArg = node.args |
|
1917 if ( |
|
1918 isinstance(firstArg, ast.Call) |
|
1919 and isinstance(firstArg.func, ast.Attribute) |
|
1920 and isinstance(firstArg.func.value, ast.Name) |
|
1921 and firstArg.func.attr == "keys" |
|
1922 and isinstance(secondArg, ast.Call) |
|
1923 and isinstance(secondArg.func, ast.Attribute) |
|
1924 and isinstance(secondArg.func.value, ast.Name) |
|
1925 and secondArg.func.attr == "values" |
|
1926 and firstArg.func.value.id == secondArg.func.value.id |
|
1927 ): |
|
1928 self.__error( |
|
1929 node.lineno - 1, node.col_offset, "Y911", firstArg.func.value.id |
|
1930 ) |
|
1931 |
|
1932 |
1903 |
1933 |
1904 # |
1934 # |
1905 # eflag: noqa = M891 |
1935 # eflag: noqa = M891 |