mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 08:30:16 +00:00
Simplify IfRequired needs parentheses condition (#6678)
This commit is contained in:
parent
2a8d24dd4b
commit
8b347cdaa9
2 changed files with 5 additions and 13 deletions
|
@ -192,13 +192,11 @@ impl Format<PyFormatContext<'_>> for MaybeParenthesizeExpression<'_> {
|
|||
|
||||
let needs_parentheses = expression.needs_parentheses(*parent, f.context());
|
||||
let needs_parentheses = match parenthesize {
|
||||
Parenthesize::IfRequired => {
|
||||
if !needs_parentheses.is_always() && f.context().node_level().is_parenthesized() {
|
||||
OptionalParentheses::Never
|
||||
} else {
|
||||
needs_parentheses
|
||||
}
|
||||
}
|
||||
Parenthesize::IfRequired => match needs_parentheses {
|
||||
OptionalParentheses::Always => OptionalParentheses::Always,
|
||||
_ if f.context().node_level().is_parenthesized() => OptionalParentheses::Never,
|
||||
needs_parentheses => needs_parentheses,
|
||||
},
|
||||
Parenthesize::Optional
|
||||
| Parenthesize::IfBreaks
|
||||
| Parenthesize::IfBreaksOrIfRequired => needs_parentheses,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue