问题
To improve code readability I need to split my ternary operator expression into multiple lines. My only idea is something like this:
very_long_function_name(
...
very_long_expression_if_the_condition_is_true
if the_condition
else another_expression_if_the_condition_is_false)
Unfortunately PyCharm claims that continuation line over-indented for visual indent
is a violation of PEP8. When I wrap the operator in braces PyCharm raises no objections, but IMHO the code is less readable then.
Is there any [semi]formal recommendation for splitting ternary operator into multiple lines?
Declaration of auxiliary functions/methods is not an option.
回答1:
Code formatting is generally too much of a matter of opinion, so I think Opinionated and automated code formatting is the solution - install and run black and cease talking about it.
来源:https://stackoverflow.com/questions/55870257/what-is-the-recommended-layout-for-splitting-ternary-operator-into-multiple-line