Skip to content

Commit

Permalink
refactor: use more descriptive variables name for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowrey committed Sep 18, 2023
1 parent 720d476 commit 2334c66
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,6 @@ pub(crate) fn use_dict_get_with_default(checker: &mut Checker, stmt_if: &ast::St
}

/// SIM401
// var = a_dict[key] if key in a_dict else "default3"
pub(crate) fn if_expr_with_dict(
checker: &mut Checker,
expr: &Expr,
Expand Down Expand Up @@ -1030,25 +1029,25 @@ pub(crate) fn if_expr_with_dict(
return;
}

let node = orelse.clone();
let node1 = *test_key.clone();
let node2 = ast::ExprAttribute {
let default_value_node = orelse.clone();
let dict_key_node = *test_key.clone();
let dict_get_node = ast::ExprAttribute {
value: expected_subscript.clone(),
attr: Identifier::new("get".to_string(), TextRange::default()),
ctx: ExprContext::Load,
range: TextRange::default(),
};
let node3 = ast::ExprCall {
func: Box::new(node2.into()),
let fixed_node = ast::ExprCall {
func: Box::new(dict_get_node.into()),
arguments: Arguments {
args: vec![node1, node],
args: vec![dict_key_node, default_value_node],
keywords: vec![],
range: TextRange::default(),
},
range: TextRange::default(),
};

let contents = checker.generator().expr(&node3.into());
let contents = checker.generator().expr(&fixed_node.into());

let mut diagnostic = Diagnostic::new(
IfElseBlockInsteadOfDictGet {
Expand Down

0 comments on commit 2334c66

Please sign in to comment.