ruff
289d1e85 - Manually parenthesize tuple expr in `B014` autofix (#6415)

Commit
2 years ago
Manually parenthesize tuple expr in `B014` autofix (#6415) ## Summary Manually add the parentheses around tuple expressions for the autofix in `B014`. This is also done in various other autofixes as well such as for [`RUF005`](https://github.com/astral-sh/ruff/blob/6df5ab40987cba7bb5681c2445caaf83ebcfbf7d/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs#L183-L184), [`UP024`](https://github.com/astral-sh/ruff/blob/6df5ab40987cba7bb5681c2445caaf83ebcfbf7d/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs#L137-L137). ### Alternate Solution An alternate solution would be to fix this in the `Generator` itself by checking if the tuple expression needs to be generated at the top-level or not. If so, then always add the parentheses. ```rust } else if level == 0 { // Top-level tuples are always parenthesized. self.p("("); let mut first = true; for elt in elts { self.p_delim(&mut first, ", "); self.unparse_expr(elt, precedence::COMMA); } self.p_if(elts.len() == 1, ","); self.p(")"); ``` ## Test Plan Add a regression test for this case in `B014`. fixes: #6412
Author
Parents
Loading