You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's possible to have line wraps in the body of a lambda if the lambda expression as a whole is parenthesized, or used in contexts such as function arguments. Currently black would give the wrapped lines the same indent as the line that lambda is on, which could cause confusion. I propose to have black automatically parenthesize the lambda's body so it could be further indented.
The current style is very confusing in my opinion, because it's hard to tell at first glance what the boundary of the lambda expression is. Since usually lambda expressions are single-line, one might be more likely to initially parse this as:
(lambdaarg1, arg2: do_something_with_the_two_args(arg1, arg2))
if (arg2isnotNone)
else (do_something_with_only_one_arg(arg1))
Describe the style change
It's possible to have line wraps in the body of a lambda if the lambda expression as a whole is parenthesized, or used in contexts such as function arguments. Currently black would give the wrapped lines the same indent as the line that
lambda
is on, which could cause confusion. I propose to have black automatically parenthesize the lambda's body so it could be further indented.Examples in the current Black style
The current style is very confusing in my opinion, because it's hard to tell at first glance what the boundary of the lambda expression is. Since usually lambda expressions are single-line, one might be more likely to initially parse this as:
Desired style
Parentheses are inserted inside the lambda's body, so it has an extra level of indentation that clearly marks the boundaries of the lambda.
Additional context
The function argument case might be similar to #2248 and #3510, both of which I also endorse.
The text was updated successfully, but these errors were encountered: