-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 multi-context managers #9222
Conversation
|
d87ba74
to
390adb4
Compare
786a2e1
to
97919f3
Compare
@@ -538,8 +538,8 @@ fn can_omit_optional_parentheses(expr: &Expr, context: &PyFormatContext) -> bool | |||
false | |||
} else if visitor.max_precedence_count > 1 { | |||
false | |||
} else if visitor.max_precedence == OperatorPrecedence::None && expr.is_lambda_expr() { | |||
// Micha: This seems to exclusively apply for lambda expressions where the body ends in a subscript. | |||
} else if visitor.max_precedence == OperatorPrecedence::None { |
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.
It seems I don't understand these rules after all :(
97919f3
to
929e728
Compare
929e728
to
7940671
Compare
/// * There's a single non-parenthesized item. The function returns [`ParenthesizeWith::Optional`] | ||
/// if the parentheses can be omitted if breaking around parenthesized sub-expressions is sufficient | ||
/// to make the expression fit. It returns [`ParenthesizeWith::IfExpands`] otherwise. | ||
/// * The only item is parenthesized and has comments. |
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.
That's a lot of cases, nice job figuring it out...
7940671
to
dc20d2a
Compare
Summary
This PR implements Black's
wrap_multiple_context_managers_in_parens
andimproved_async_statements_handling
preview styles.Closes #8889
Closes #8890
Test Plan