mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 21:15:19 +00:00
Format StmtAugAssign (#5655)
## Summary Format statements such as `tree_depth += 1`. This is a statement that does not allow any line breaks, the only thing to be mindful of is to parenthesize the assigned expression Jaccard index on django: 0.915 -> 0.918 ## Test Plan black tests, and two new tests, a basic one and one that ensures that the child gets parentheses. I ran the django stability check.
This commit is contained in:
parent
15c7b6bcf7
commit
b7794f855b
6 changed files with 56 additions and 27 deletions
|
@ -1,4 +1,6 @@
|
|||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::{AsFormat, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::{space, text};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::StmtAugAssign;
|
||||
|
||||
|
@ -7,6 +9,22 @@ pub struct FormatStmtAugAssign;
|
|||
|
||||
impl FormatNodeRule<StmtAugAssign> for FormatStmtAugAssign {
|
||||
fn fmt_fields(&self, item: &StmtAugAssign, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
let StmtAugAssign {
|
||||
target,
|
||||
op,
|
||||
value,
|
||||
range: _,
|
||||
} = item;
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
target.format(),
|
||||
space(),
|
||||
op.format(),
|
||||
text("="),
|
||||
space(),
|
||||
value.format().with_options(Parenthesize::IfBreaks)
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue