What is the recommended layout for splitting ternary operator into multiple lines?

谁说胖子不能爱 提交于 2019-12-11 14:11:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!