From 0bb9d7381be07e22abced8eb4d3a936ba487249e Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sat, 23 Sep 2023 23:25:59 +0200 Subject: [PATCH] STY: SIM102 --- flake8_simplify/rules/ast_call.py | 43 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/flake8_simplify/rules/ast_call.py b/flake8_simplify/rules/ast_call.py index c6a2831..666beb3 100644 --- a/flake8_simplify/rules/ast_call.py +++ b/flake8_simplify/rules/ast_call.py @@ -274,29 +274,28 @@ def get_sim911(node: ast.AST) -> List[Tuple[int, int, str]]: ) errors: List[Tuple[int, int, str]] = [] - if isinstance(node, ast.Call): + if isinstance(node, ast.Call) and ( + isinstance(node.func, ast.Name) + and node.func.id == "zip" + and len(node.args) == 2 + ): + first_arg, second_arg = node.args if ( - isinstance(node.func, ast.Name) - and node.func.id == "zip" - and len(node.args) == 2 + isinstance(first_arg, ast.Call) + and isinstance(first_arg.func, ast.Attribute) + and isinstance(first_arg.func.value, ast.Name) + and first_arg.func.attr == "keys" + and isinstance(second_arg, ast.Call) + and isinstance(second_arg.func, ast.Attribute) + and isinstance(second_arg.func.value, ast.Name) + and second_arg.func.attr == "values" + and first_arg.func.value.id == second_arg.func.value.id ): - first_arg, second_arg = node.args - if ( - isinstance(first_arg, ast.Call) - and isinstance(first_arg.func, ast.Attribute) - and isinstance(first_arg.func.value, ast.Name) - and first_arg.func.attr == "keys" - and isinstance(second_arg, ast.Call) - and isinstance(second_arg.func, ast.Attribute) - and isinstance(second_arg.func.value, ast.Name) - and second_arg.func.attr == "values" - and first_arg.func.value.id == second_arg.func.value.id - ): - errors.append( - ( - node.lineno, - node.col_offset, - RULE.format(name=first_arg.func.value.id), - ) + errors.append( + ( + node.lineno, + node.col_offset, + RULE.format(name=first_arg.func.value.id), ) + ) return errors