From 82ec884a61dbc9edf5793ffc8001f7b06c73fc33 Mon Sep 17 00:00:00 2001 From: Florian Best Date: Wed, 1 Feb 2023 00:25:22 +0100 Subject: [PATCH] feat: let SIM210 return expressions without bool() wrapping (#2410) (#2426) --- src/rules/flake8_simplify/rules/ast_ifexp.rs | 23 ++++++++++--------- ...ke8_simplify__tests__SIM210_SIM210.py.snap | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/rules/flake8_simplify/rules/ast_ifexp.rs b/src/rules/flake8_simplify/rules/ast_ifexp.rs index da915e8caa..48068ea3d1 100644 --- a/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -35,18 +35,19 @@ pub fn explicit_true_false_in_ifexpr( Range::from_located(expr), ); if checker.patch(diagnostic.kind.rule()) { + let bool_expr = match test.node { + ExprKind::Compare { .. } => test.clone(), + _ => create_expr(ExprKind::Call { + func: Box::new(create_expr(ExprKind::Name { + id: "bool".to_string(), + ctx: ExprContext::Load, + })), + args: vec![test.clone()], + keywords: vec![], + }), + }; diagnostic.amend(Fix::replacement( - unparse_expr( - &create_expr(ExprKind::Call { - func: Box::new(create_expr(ExprKind::Name { - id: "bool".to_string(), - ctx: ExprContext::Load, - })), - args: vec![test.clone()], - keywords: vec![], - }), - checker.stylist, - ), + unparse_expr(&bool_expr, checker.stylist), expr.location, expr.end_location.unwrap(), )); diff --git a/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM210_SIM210.py.snap b/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM210_SIM210.py.snap index 40b932e6c3..a12b33fe4d 100644 --- a/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM210_SIM210.py.snap +++ b/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM210_SIM210.py.snap @@ -32,7 +32,7 @@ expression: diagnostics column: 29 fix: content: - - bool(b != c) + - b != c location: row: 3 column: 4