mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-02 01:42:25 +00:00
Implement StmtReturn (#4960)
* Implement StmtPass This implements StmtPass as `pass`. The snapshot diff is small because pass mainly occurs in bodies and function (#4951) and if/for bodies. * Implement StmtReturn This implements StmtReturn as `return` or `return {value}`. The snapshot diff is small because return occurs in functions (#4951)
This commit is contained in:
parent
c8442e91ce
commit
467df23e65
2 changed files with 19 additions and 5 deletions
|
@ -1,5 +1,7 @@
|
|||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::{AsFormat, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::{space, text};
|
||||
use ruff_formatter::{write, Buffer, Format, FormatResult};
|
||||
use rustpython_parser::ast::StmtReturn;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -7,6 +9,18 @@ pub struct FormatStmtReturn;
|
|||
|
||||
impl FormatNodeRule<StmtReturn> for FormatStmtReturn {
|
||||
fn fmt_fields(&self, item: &StmtReturn, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
let StmtReturn { range: _, value } = item;
|
||||
if let Some(value) = value {
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
text("return"),
|
||||
space(),
|
||||
value.format().with_options(Parenthesize::IfBreaks)
|
||||
]
|
||||
)
|
||||
} else {
|
||||
text("return").fmt(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue