-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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)
- Loading branch information
Showing
2 changed files
with
19 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
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)] | ||
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) | ||
} | ||
} | ||
} |