mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 04:55:09 +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 = expression.needs_parentheses(*parent, f.context());
|
||||||
let needs_parentheses = match parenthesize {
|
let needs_parentheses = match parenthesize {
|
||||||
Parenthesize::IfRequired => {
|
Parenthesize::IfRequired => match needs_parentheses {
|
||||||
if !needs_parentheses.is_always() && f.context().node_level().is_parenthesized() {
|
OptionalParentheses::Always => OptionalParentheses::Always,
|
||||||
OptionalParentheses::Never
|
_ if f.context().node_level().is_parenthesized() => OptionalParentheses::Never,
|
||||||
} else {
|
needs_parentheses => needs_parentheses,
|
||||||
needs_parentheses
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
Parenthesize::Optional
|
Parenthesize::Optional
|
||||||
| Parenthesize::IfBreaks
|
| Parenthesize::IfBreaks
|
||||||
| Parenthesize::IfBreaksOrIfRequired => needs_parentheses,
|
| Parenthesize::IfBreaksOrIfRequired => needs_parentheses,
|
||||||
|
|
|
@ -23,12 +23,6 @@ pub(crate) enum OptionalParentheses {
|
||||||
Never,
|
Never,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OptionalParentheses {
|
|
||||||
pub(crate) const fn is_always(self) -> bool {
|
|
||||||
matches!(self, OptionalParentheses::Always)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) trait NeedsParentheses {
|
pub(crate) trait NeedsParentheses {
|
||||||
/// Determines if this object needs optional parentheses or if it is safe to omit the parentheses.
|
/// Determines if this object needs optional parentheses or if it is safe to omit the parentheses.
|
||||||
fn needs_parentheses(
|
fn needs_parentheses(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue