Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add style setting to allow for function continuation indent width #1024

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions yapf/yapflib/format_decision_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,12 @@ def _IndentWithContinuationAlignStyle(self, column):
return column
align_style = style.Get('CONTINUATION_ALIGN_STYLE')
if align_style == 'FIXED':
return ((self.line.depth * style.Get('INDENT_WIDTH')) +
style.Get('CONTINUATION_INDENT_WIDTH'))
if _IsFunctionDef(self.line.first):
indent_width = style.GetOrDefault('FUNCTION_CONTINUATION_INDENT_WIDTH',
style.Get('CONTINUATION_INDENT_WIDTH'))
else:
indent_width = style.Get('CONTINUATION_INDENT_WIDTH')
return ((self.line.depth * style.Get('INDENT_WIDTH')) + indent_width)
if align_style == 'VALIGN-RIGHT':
indent_width = style.Get('INDENT_WIDTH')
return indent_width * int((column + indent_width - 1) / indent_width)
Expand Down
5 changes: 5 additions & 0 deletions yapf/yapflib/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def method():
config = {
'key1': 'value1'
}"""),
FUNCTION_CONTINUATION_INDENT_WIDTH=textwrap.dedent("""\
Indent width used for function definition line continuations. Defaults to
CONTINUATION_INDENT_WIDTH."""),
I18N_COMMENT=textwrap.dedent("""\
The regex for an i18n comment. The presence of this comment stops
reformatting of that line, because the comments are required to be
Expand Down Expand Up @@ -438,6 +441,7 @@ def CreatePEP8Style():
DISABLE_ENDING_COMMA_HEURISTIC=False,
EACH_DICT_ENTRY_ON_SEPARATE_LINE=True,
FORCE_MULTILINE_DICT=False,
FUNCTION_CONTINUATION_INDENT_WIDTH=4,
I18N_COMMENT='',
I18N_FUNCTION_CALL='',
INDENT_DICTIONARY_VALUE=False,
Expand Down Expand Up @@ -626,6 +630,7 @@ def _IntOrIntListConverter(s):
DISABLE_ENDING_COMMA_HEURISTIC=_BoolConverter,
EACH_DICT_ENTRY_ON_SEPARATE_LINE=_BoolConverter,
FORCE_MULTILINE_DICT=_BoolConverter,
FUNCTION_CONTINUATION_INDENT_WIDTH=int,
I18N_COMMENT=str,
I18N_FUNCTION_CALL=_StringListConverter,
INDENT_DICTIONARY_VALUE=_BoolConverter,
Expand Down