将三元运算符拆分为多行的建议布局是什么?

问题描述 投票:0回答:1

为了提高代码可读性,我需要将三元运算符表达式拆分为多行。我唯一的想法是这样的:

very_long_function_name(
    ...
    very_long_expression_if_the_condition_is_true
      if the_condition
      else another_expression_if_the_condition_is_false)

不幸的是,PyCharm声称continuation line over-indented for visual indent违反了PEP8。当我将操作符包装在大括号中时,PyCharm没有提出反对意见,但恕我直言,代码的可读性较低。

是否有任何[半]正式建议将三元运算符分成多行?

辅助功能/方法的声明不是一种选择。

python pycharm indentation ternary-operator pep8
1个回答
1
投票

代码格式化通常太过于意见,所以我认为Opinionated and automated code formatting是解决方案 - 安装并运行black并停止谈论它。

© www.soinside.com 2019 - 2024. All rights reserved.