Fix multiple # in comment warning.

pull/1005/head
Bill Wendling 9 months ago
parent f210c396e8
commit b96fbe9627
  1. 3
      yapf/pyparser/pyparser.py
  2. 8
      yapf/pyparser/split_penalty_visitor.py
  3. 2
      yapf/yapflib/split_penalty.py

@ -66,6 +66,7 @@ def ParseCode(unformatted_source, filename='<unknown>'):
try:
ast_tree = ast.parse(unformatted_source, filename)
ast.fix_missing_locations(ast_tree)
readline = py3compat.StringIO(unformatted_source).readline
tokens = tokenize.generate_tokens(readline)
except Exception:
@ -74,8 +75,8 @@ def ParseCode(unformatted_source, filename='<unknown>'):
logical_lines = _CreateLogicalLines(tokens)
# Process the logical lines.
ast.fix_missing_locations(ast_tree)
split_penalty_visitor.SplitPenalty(logical_lines).visit(ast_tree)
return logical_lines

@ -61,6 +61,11 @@ class SplitPenalty(ast.NodeVisitor):
# Don't split after the '@'.
decorator_range[0].split_penalty = split_penalty.UNBREAKABLE
for token in tokens[1:]:
if token.value == '(':
break
_SetPenalty(token, split_penalty.UNBREAKABLE)
if node.returns:
start_index = pyutils.GetTokenIndex(tokens,
pyutils.TokenStart(node.returns))
@ -84,9 +89,6 @@ class SplitPenalty(ast.NodeVisitor):
# body=[...],
# decorator_list=[Expr_1, Expr_2, ..., Expr_n],
# keywords=[])
tokens = self._GetTokens(node)
_IncreasePenalty(tokens[1], split_penalty.UNBREAKABLE)
return self.visit_FunctionDef(node)
def visit_ClassDef(self, node):

@ -20,7 +20,7 @@ VERY_STRONGLY_CONNECTED = 5000
STRONGLY_CONNECTED = 2500
#############################################################################
### Grammar-specific penalties - should be <= 1000 ###
# Grammar-specific penalties - should be <= 1000 #
#############################################################################
# Lambdas shouldn't be split unless absolutely necessary or if

Loading…
Cancel
Save