yapf icon indicating copy to clipboard operation
yapf copied to clipboard

`split_before_arithmetic_operator` is ignored?

Open hydrargyrum opened this issue 4 years ago • 3 comments

Despite this simple config file:

[style]
based_on_style = pep8
split_before_arithmetic_operator = true

yapf splits after the operator, not before as it should:

% ~/.local/bin/yapf --diff --style op.yapf op.py
--- op.py	(original)
+++ op.py	(reformatted)
@@ -1 +1,3 @@
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccccccccccccccccccccccccccccccccc)
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
+    bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +
+    cccccccccccccccccccccccccccccccccccccccccccccc)

SPLIT_BEFORE_ARITHMETIC_OPERATOR

Set to True to prefer splitting before +, -, *, /, //, or @ rather than after.

hydrargyrum avatar Jan 21 '20 14:01 hydrargyrum

Works fine for me with yapf 0.29.0. I don't know if it could be a version problem, but I leave it as a background.

apdelsm avatar Feb 24 '20 15:02 apdelsm

Have the same issue in 0.30.0. Also it seems missing *, / and //

_ARITH_OPS = frozenset({'PLUS', 'MINUS'})

def Visit_arith_expr(self, node):  # pylint: disable=invalid-name
  # arith_expr ::= term (('+'|'-') term)*
  self.DefaultNodeVisit(node)
  _IncreasePenalty(node, ARITH_EXPR)
  _SetExpressionOperandPenalty(node, self._ARITH_OPS)

elbaro avatar Jun 03 '20 17:06 elbaro

The '*', '/', '@', and '//' operators are taken care of in Visit_term.

bwendling avatar Jan 08 '22 08:01 bwendling