Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter: Yield / YieldFrom (good first issue) #5916

Closed
2 tasks
Tracked by #4798
MichaReiser opened this issue Jul 20, 2023 · 1 comment · Fixed by #5921
Closed
2 tasks
Tracked by #4798

Formatter: Yield / YieldFrom (good first issue) #5916

MichaReiser opened this issue Jul 20, 2023 · 1 comment · Fixed by #5921
Labels
formatter Related to the formatter good first issue Good for newcomers

Comments

@MichaReiser
Copy link
Member

MichaReiser commented Jul 20, 2023

  • yield
  • yield..from
@MichaReiser
Copy link
Member Author

MichaReiser commented Jul 20, 2023

@qdegraaf has shown interest in working on this

You can find the dummy implementation here

use crate::context::PyFormatContext;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprYield;
#[derive(Default)]
pub struct FormatExprYield;
impl FormatNodeRule<ExprYield> for FormatExprYield {
fn fmt_fields(&self, item: &ExprYield, f: &mut PyFormatter) -> FormatResult<()> {
write!(f, [not_yet_implemented(item)])
}
}
impl NeedsParentheses for ExprYield {
fn needs_parentheses(
&self,
_parent: AnyNodeRef,
_context: &PyFormatContext,
) -> OptionalParentheses {
OptionalParentheses::Multiline
}
}

I recommend taking a look at the raise stmt PR #5595 and/or formatting of await expressions because I assume the formatting would be similar.

Oh, and I should not forget the documentation

@zanieb zanieb added the good first issue Good for newcomers label Jul 20, 2023
@konstin konstin added the formatter Related to the formatter label Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants