Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap return-bool-condition-directly fixes in bool() #2240

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/rules/flake8_simplify/rules/ast_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,14 @@ pub fn return_bool_condition_directly(checker: &mut Checker, stmt: &Stmt) {
&& !has_comments_in(Range::from_located(stmt), checker.locator)
{
let return_stmt = create_stmt(StmtKind::Return {
value: Some(test.clone()),
value: Some(Box::new(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_stmt(&return_stmt, checker.stylist),
Expand Down
2 changes: 1 addition & 1 deletion src/rules/flake8_simplify/rules/ast_ifexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn explicit_true_false_in_ifexpr(
id: "bool".to_string(),
ctx: ExprContext::Load,
})),
args: vec![create_expr(test.node.clone())],
args: vec![test.clone()],
keywords: vec![],
}),
checker.stylist,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ expression: diagnostics
column: 20
fix:
content:
- return a
- return bool(a)
location:
row: 3
column: 4
Expand All @@ -30,7 +30,7 @@ expression: diagnostics
column: 20
fix:
content:
- return b
- return bool(b)
location:
row: 13
column: 4
Expand All @@ -48,7 +48,7 @@ expression: diagnostics
column: 24
fix:
content:
- return b
- return bool(b)
location:
row: 24
column: 8
Expand Down