mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-15 06:45:21 +00:00
Format class
definitions (#5289)
This commit is contained in:
parent
7d4f8e59da
commit
f7e1cf4b51
27 changed files with 914 additions and 541 deletions
|
@ -26,6 +26,8 @@ pub(super) fn default_expression_needs_parentheses(
|
|||
#[allow(clippy::if_same_then_else)]
|
||||
if parenthesize.is_always() {
|
||||
Parentheses::Always
|
||||
} else if parenthesize.is_never() {
|
||||
Parentheses::Never
|
||||
}
|
||||
// `Optional` or `Preserve` and expression has parentheses in source code.
|
||||
else if !parenthesize.is_if_breaks() && is_expression_parenthesized(node, source) {
|
||||
|
@ -58,7 +60,11 @@ pub enum Parenthesize {
|
|||
/// Parenthesizes the expression only if it doesn't fit on a line.
|
||||
IfBreaks,
|
||||
|
||||
/// Always adds parentheses
|
||||
Always,
|
||||
|
||||
/// Never adds parentheses. Parentheses are handled by the caller.
|
||||
Never,
|
||||
}
|
||||
|
||||
impl Parenthesize {
|
||||
|
@ -66,6 +72,10 @@ impl Parenthesize {
|
|||
matches!(self, Parenthesize::Always)
|
||||
}
|
||||
|
||||
pub(crate) const fn is_never(self) -> bool {
|
||||
matches!(self, Parenthesize::Never)
|
||||
}
|
||||
|
||||
pub(crate) const fn is_if_breaks(self) -> bool {
|
||||
matches!(self, Parenthesize::IfBreaks)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue