Avoid broken autofix for SIM103 with elif (#1944)

Also adjusts the generator to avoid the extra parentheses (and skips commented `if` statements).

Closes #1943.
This commit is contained in:
Charlie Marsh
2023-01-17 22:03:17 -05:00
committed by GitHub
parent b9bb5acff8
commit 84d1df08be
5 changed files with 76 additions and 13 deletions

View File

@@ -227,10 +227,13 @@ impl<'a> Generator<'a> {
}
}
StmtKind::Return { value } => {
// TODO(charlie): Revisit precedence. In particular, look at how Astor handles
// precedence.
// See: https://github.com/berkerpeksag/astor/blob/8342d6aa5dcdcf20f89a19057527510c245c7a2e/astor/code_gen.py#L86
statement!({
if let Some(expr) = value {
self.p("return ");
self.unparse_expr(expr, precedence::ATOM);
self.unparse_expr(expr, 1);
} else {
self.p("return");
}