Skip to content

Commit

Permalink
Merge d96a0f4 into 690d339
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthchirp committed Feb 14, 2018
2 parents 690d339 + d96a0f4 commit 6b8d9f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion yapf/yapflib/blank_line_calculator.py
Expand Up @@ -27,6 +27,7 @@
from yapf.yapflib import py3compat
from yapf.yapflib import pytree_utils
from yapf.yapflib import pytree_visitor
from yapf.yapflib import style

_NO_BLANK_LINES = 1
_ONE_BLANK_LINE = 2
Expand Down Expand Up @@ -155,7 +156,7 @@ def _GetNumNewlines(self, node):
if self.last_was_decorator:
return _NO_BLANK_LINES
elif self._IsTopLevel(node):
return _TWO_BLANK_LINES
return 1 + style.Get('BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION')
return _ONE_BLANK_LINE

def _SetNumNewlines(self, node, num_newlines):
Expand Down
9 changes: 5 additions & 4 deletions yapf/yapflib/reformatter.py
Expand Up @@ -479,9 +479,9 @@ def _CalculateNumberOfNewlines(first_token, indent_depth, prev_uwline,
prev_last_token = prev_uwline.last
if prev_last_token.is_docstring:
if (not indent_depth and first_token.value in {'class', 'def', 'async'}):
# Separate a class or function from the module-level docstring with two
# blank lines.
return TWO_BLANK_LINES
# Separate a class or function from the module-level docstring with
# appropriate number of blank lines.
return 1 + style.Get('BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION')
if _NoBlankLinesBeforeCurrentToken(prev_last_token.value, first_token,
prev_last_token):
return NO_BLANK_LINES
Expand Down Expand Up @@ -509,7 +509,8 @@ def _CalculateNumberOfNewlines(first_token, indent_depth, prev_uwline,
if final_lines[index - 1].first.value == '@':
final_lines[index].first.AdjustNewlinesBefore(NO_BLANK_LINES)
else:
prev_last_token.AdjustNewlinesBefore(TWO_BLANK_LINES)
prev_last_token.AdjustNewlinesBefore(
1 + style.Get('BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION'))
if first_token.newlines is not None:
pytree_utils.SetNodeAnnotation(
first_token.node, pytree_utils.Annotation.NEWLINES, None)
Expand Down
5 changes: 5 additions & 0 deletions yapf/yapflib/style.py
Expand Up @@ -71,6 +71,9 @@ def method():
..."""),
BLANK_LINE_BEFORE_CLASS_DOCSTRING=textwrap.dedent("""\
Insert a blank line before a class-level docstring."""),
BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION=textwrap.dedent("""\
Number of blank lines surrounding top-level function and class
definitions."""),
COALESCE_BRACKETS=textwrap.dedent("""\
Do not split consecutive brackets. Only relevant when
dedent_closing_brackets is set. For example:
Expand Down Expand Up @@ -240,6 +243,7 @@ def CreatePEP8Style():
ALLOW_SPLIT_BEFORE_DICT_VALUE=True,
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=False,
BLANK_LINE_BEFORE_CLASS_DOCSTRING=False,
BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION=2,
COALESCE_BRACKETS=False,
COLUMN_LIMIT=79,
CONTINUATION_INDENT_WIDTH=4,
Expand Down Expand Up @@ -370,6 +374,7 @@ def _BoolConverter(s):
ALLOW_SPLIT_BEFORE_DICT_VALUE=_BoolConverter,
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=_BoolConverter,
BLANK_LINE_BEFORE_CLASS_DOCSTRING=_BoolConverter,
BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION=int,
COALESCE_BRACKETS=_BoolConverter,
COLUMN_LIMIT=int,
CONTINUATION_INDENT_WIDTH=int,
Expand Down

0 comments on commit 6b8d9f3

Please sign in to comment.