Repository: google/yapf
Pull request #724 (2019-05-10 11:15:07)

`spaces_before_comment` parsing for `--style-help`
This patch fixes issue observed running `yapf --style-help` with setting `spaces_before_comment` set to the range. See #723 for more information 


Patch:
diff --git a/CHANGELOG b/CHANGELOG
index 61be588..9ca199c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,9 +13,6 @@
 ### Fixed
 - `BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=False` wasn't honored because the
   number of newlines was erroneously calculated beforehand.
-- Lambda expressions shouldn't have an increased split penalty applied to the
-  'lambda' keyword. This prevents them from being properly formatted when they're
-  arguments to functions.
 
 ## [0.27.0] 2019-04-07
 ### Added
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 62e2a5f..284b13f 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -13,3 +13,4 @@ Bill Wendling <morbo@google.com>
 Eli Bendersky <eliben@google.com>
 Sam Clegg <sbc@google.com>
 Łukasz Langa <ambv@fb.com>
+Oleg Butuzov <butuzov@made.ua>
diff --git a/README.rst b/README.rst
index 995b332..b139e5d 100644
--- a/README.rst
+++ b/README.rst
@@ -575,19 +575,19 @@ Knobs
     ``b`` in this code:
 
     .. code-block:: python
-      
-      abcdef(
-          aReallyLongThing: int,
-          b: [Int,
-              Int])
+
+    abcdef(
+        aReallyLongThing: int,
+        b: [Int,
+            Int])
    
     With the new knob this is split as:
 
     .. code-block:: python
-      
-      abcdef(
-          aReallyLongThing: int,
-          b: [Int, Int])
+
+    abcdef(
+        aReallyLongThing: int,
+        b: [Int, Int])
 
 ``SPLIT_BEFORE_BITWISE_OPERATOR``
     Set to ``True`` to prefer splitting before ``&``, ``|`` or ``^`` rather
diff --git a/yapf/__init__.py b/yapf/__init__.py
index fa9c60e..d88d15c 100644
--- a/yapf/__init__.py
+++ b/yapf/__init__.py
@@ -149,7 +149,7 @@ def main(argv):
         print('#', line and ' ' or '', line, sep='')
       option_value = style.Get(option)
       if isinstance(option_value, set) or isinstance(option_value, list):
-        option_value = ', '.join(option_value)
+        option_value = ', '.join(map(str, option_value))
       print(option.lower(), '=', option_value, sep='')
       print()
     return 0
diff --git a/yapf/yapflib/format_decision_state.py b/yapf/yapflib/format_decision_state.py
index ab7a40b..24ebdff 100644
--- a/yapf/yapflib/format_decision_state.py
+++ b/yapf/yapflib/format_decision_state.py
@@ -950,7 +950,7 @@ class FormatDecisionState(object):
 
     Arguments:
       opening: (FormatToken) The unwrapped line we're currently processing.
-
+      
     Returns:
       True if the container fits on the start line.
     """
diff --git a/yapf/yapflib/split_penalty.py b/yapf/yapflib/split_penalty.py
index 7f86d96..6c6a79f 100644
--- a/yapf/yapflib/split_penalty.py
+++ b/yapf/yapflib/split_penalty.py
@@ -129,9 +129,9 @@ class _SplitPenaltyAssigner(pytree_visitor.PyTreeVisitor):
             break
 
     if allow_multiline_lambdas:
-      _SetExpressionPenalty(node, STRONGLY_CONNECTED)
+      _SetStronglyConnected(node)
     else:
-      _SetExpressionPenalty(node, VERY_STRONGLY_CONNECTED)
+      _SetVeryStronglyConnected(node)
 
   def Visit_parameters(self, node):  # pylint: disable=invalid-name
     # parameters ::= '(' [typedargslist] ')'


Test patch:
diff --git a/yapftests/reformatter_buganizer_test.py b/yapftests/reformatter_buganizer_test.py
index 935f98e..f128073 100644
--- a/yapftests/reformatter_buganizer_test.py
+++ b/yapftests/reformatter_buganizer_test.py
@@ -28,17 +28,6 @@ class BuganizerFixes(yapf_test_helper.YAPFTest):
   def setUpClass(cls):
     style.SetGlobalStyle(style.CreateChromiumStyle())
 
-  def testB26521719(self):
-    code = """\
-class _():
-
-  def _(self):
-    self.stubs.Set(some_type_of_arg, 'ThisIsAStringArgument',
-                   lambda *unused_args, **unused_kwargs: fake_resolver)
-"""
-    uwlines = yapf_test_helper.ParseAndUnwrap(code)
-    self.assertCodeEqual(code, reformatter.Reformat(uwlines))
-
   def testB122541552(self):
     code = """\
 # pylint: disable=g-explicit-bool-comparison,singleton-comparison
diff --git a/yapftests/split_penalty_test.py b/yapftests/split_penalty_test.py
index 895445c..efcebfb 100644
--- a/yapftests/split_penalty_test.py
+++ b/yapftests/split_penalty_test.py
@@ -139,7 +139,7 @@ class SplitPenaltyTest(yapf_test_helper.YAPFTest):
       """)
     tree = self._ParseAndComputePenalties(code)
     self._CheckPenalties(tree, [
-        ('lambda', None),
+        ('lambda', VERY_STRONGLY_CONNECTED),
         ('a', VERY_STRONGLY_CONNECTED),
         (',', VERY_STRONGLY_CONNECTED),
         ('b', VERY_STRONGLY_CONNECTED),
@@ -180,7 +180,7 @@ class SplitPenaltyTest(yapf_test_helper.YAPFTest):
         (',', None),
         ('y', None),
         ('(', UNBREAKABLE),
-        ('lambda', STRONGLY_CONNECTED),
+        ('lambda', VERY_STRONGLY_CONNECTED),
         ('a', VERY_STRONGLY_CONNECTED),
         (':', VERY_STRONGLY_CONNECTED),
         ('23', VERY_STRONGLY_CONNECTED),
diff --git a/yapftests/subtype_assigner_test.py b/yapftests/subtype_assigner_test.py
index ef864f8..8132c68 100644
--- a/yapftests/subtype_assigner_test.py
+++ b/yapftests/subtype_assigner_test.py
@@ -159,7 +159,7 @@ class SubtypeAssignerTest(yapf_test_helper.YAPFTest):
          ('3', [format_token.Subtype.NONE]),
          (')', [format_token.Subtype.NONE]),
          ('>>', {format_token.Subtype.BINARY_OPERATOR}),
-         ('1', [format_token.Subtype.NONE]),],
+         ('1', [format_token.Subtype.NONE]), ],
     ])  # yapf: disable
 
   def testArithmeticOperators(self):
@@ -201,7 +201,7 @@ class SubtypeAssignerTest(yapf_test_helper.YAPFTest):
          (')', [format_token.Subtype.NONE]),
          ('//', {format_token.Subtype.BINARY_OPERATOR,
                  format_token.Subtype.M_EXPR_OPERATOR}),
-         ('1', [format_token.Subtype.NONE]),],
+         ('1', [format_token.Subtype.NONE]), ],
     ])  # yapf: disable
 
   def testSubscriptColon(self):
@@ -234,7 +234,7 @@ class SubtypeAssignerTest(yapf_test_helper.YAPFTest):
          ('*', {format_token.Subtype.UNARY_OPERATOR,
                 format_token.Subtype.VARARGS_STAR}),
          ('b', [format_token.Subtype.NONE]),
-         (']', [format_token.Subtype.NONE]),],
+         (']', [format_token.Subtype.NONE]), ],
     ])  # yapf: disable