mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
format StmtWith (#5350)
This commit is contained in:
parent
49cabca3e7
commit
d00559e42a
13 changed files with 380 additions and 80 deletions
|
@ -1,4 +1,6 @@
|
|||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::WithItem;
|
||||
|
||||
|
@ -7,6 +9,22 @@ pub struct FormatWithItem;
|
|||
|
||||
impl FormatNodeRule<WithItem> for FormatWithItem {
|
||||
fn fmt_fields(&self, item: &WithItem, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
let WithItem {
|
||||
range: _,
|
||||
context_expr,
|
||||
optional_vars,
|
||||
} = item;
|
||||
|
||||
let inner = format_with(|f| {
|
||||
write!(
|
||||
f,
|
||||
[context_expr.format().with_options(Parenthesize::IfBreaks)]
|
||||
)?;
|
||||
if let Some(optional_vars) = optional_vars {
|
||||
write!(f, [space(), text("as"), space(), optional_vars.format()])?;
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
write!(f, [group(&inner)])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue