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

Consolidate ExprYield/ExprYieldFrom into AnyExpressionYield #6121

Closed
wants to merge 4 commits into from
Closed

Consolidate ExprYield/ExprYieldFrom into AnyExpressionYield #6121

wants to merge 4 commits into from

Conversation

qdegraaf
Copy link
Contributor

Summary

Removes some duplicated logic by consolidating both yield expressions into one enum, as suggested by @MichaReiser in #5921 (review)

Test Plan

Existing tests and functionality were checked to be unchanged, this is a pure refactor PR

Comment on lines +5 to +9
use ruff_formatter::formatter::Formatter;
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::{Format, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprYield;
use ruff_text_size::TextRange;
Copy link
Member

@MichaReiser MichaReiser Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You should get Formatter, Format, FormatResult, and all the inports from ruff_formatter::preludeautomatically by usingcrate::prelude::*` (Meaning, we could remove those)

Comment on lines +224 to +227
Expr::Yield(expr) => AnyExpressionYield::from(expr).needs_parentheses(parent, context),
Expr::YieldFrom(expr) => {
AnyExpressionYield::from(expr).needs_parentheses(parent, context)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would keep the impl NeedsParentheses for ExprYield and ExprYieldFrom so that callers (including the call here) don't need to know that the implementation is shared by calling into AnyExpressionYield::from(expr).needs_parentheses

@zanieb
Copy link
Member

zanieb commented Jul 27, 2023

Hey @qdegraaf — sorry about this but we needed to remove a commit from the main branch so I've changed the base of your branch to fix the history. Please let me know if you have any questions or problems!

@qdegraaf qdegraaf closed this by deleting the head repository Jul 27, 2023
@qdegraaf
Copy link
Contributor Author

qdegraaf commented Jul 27, 2023

Hey @qdegraaf — sorry about this but we needed to remove a commit from the main branch so I've changed the base of your branch to fix the history. Please let me know if you have any questions or problems!

Hey @zanieb. Thanks for the heads up. I got too trigger happy anyway and refreshed my fork forgetting I had a couple other PRs open as well. Reopened this one in: #6127

FYI @konstin @MichaReiser due to previous reviews

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants