mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
use ruff_python_ast::ExprAwait;
|
|
|
|
use ruff_formatter::write;
|
|
use ruff_python_ast::node::AnyNodeRef;
|
|
|
|
use crate::expression::maybe_parenthesize_expression;
|
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parenthesize};
|
|
use crate::prelude::*;
|
|
use crate::FormatNodeRule;
|
|
|
|
#[derive(Default)]
|
|
pub struct FormatExprAwait;
|
|
|
|
impl FormatNodeRule<ExprAwait> for FormatExprAwait {
|
|
fn fmt_fields(&self, item: &ExprAwait, f: &mut PyFormatter) -> FormatResult<()> {
|
|
let ExprAwait { range: _, value } = item;
|
|
|
|
write!(
|
|
f,
|
|
[
|
|
text("await"),
|
|
space(),
|
|
maybe_parenthesize_expression(value, item, Parenthesize::IfRequired)
|
|
]
|
|
)
|
|
}
|
|
}
|
|
|
|
impl NeedsParentheses for ExprAwait {
|
|
fn needs_parentheses(
|
|
&self,
|
|
parent: AnyNodeRef,
|
|
_context: &PyFormatContext,
|
|
) -> OptionalParentheses {
|
|
if parent.is_expr_await() {
|
|
OptionalParentheses::Always
|
|
} else {
|
|
OptionalParentheses::Multiline
|
|
}
|
|
}
|
|
}
|