-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Parenthesize singleton yield tuples #3912
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
diff-shades results comparing this PR (ebefed8) to main (1b08cbc). The full diff is available in the logs under the "Generate HTML diff report" step.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran this diff also on our internal codebase, which very heavily uses yield because of https://github.com/quora/asynq. Most of the changes are clear improvements, but I noticed a few cases like this:
- content_type = yield (
- a.model.tribe.item.TribeItem(tribe_item_id).get_content_type.asynq()
- )
+ content_type = yield a.model.tribe.item.TribeItem(
+ tribe_item_id
+ ).get_content_type.asynq()
Here the old formatting seems better.
There are also cases like this:
cant_edit = (
- yield a.controller.tribe.item.is_tribe_answer_and_cant_edit.asynq(
- self.aid, self.viewer
+ yield (
+ a.controller.tribe.item.is_tribe_answer_and_cant_edit.asynq(
+ self.aid, self.viewer
+ )
)
)
Where ideally we should remove the outer set of parentheses.
Linking #1553, another issue with how we manage yields; it may make sense to tackle them together.
@@ -11,6 +11,8 @@ | |||
<!-- Changes that affect Black's stable style --> | |||
|
|||
- Fix comments getting removed from inside parenthesized strings (#3909) | |||
- Parenthesize singleton tuples in `yield` expressions as they already are in `return` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to go in the preview style, not the stable style. (That's also why CI is failing.)
Description
Closes #3851
Please let me know if I should be going along a different path c^:
I had originally intended to make a
visit_yield_expr = partial(v, keywords={"yield"}, parens={"yield"})
to be more similar toreturn
alongside this, but that doesn't work sinceyield
can be an expression butreturn
can't.black/src/black/linegen.py
Line 527 in 1b08cbc
Checklist - did you ...
CHANGES.md
if necessary?