aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlmaz <hsyqixco@protonmail.com>2021-07-13 04:04:00 +0300
committerGitHub <noreply@github.com>2021-07-12 18:04:00 -0700
commit69bd4fec66942bc3dabf5816b7fa22de9e3ec513 (patch)
treecf6b97548b21399b26512a8d9007e540b0541ff3
parentaf43190bb7981f2dc56ea43db0c1a5fe02791bd2 (diff)
downloadyapf-69bd4fec66942bc3dabf5816b7fa22de9e3ec513.tar.gz
Merge else clause's nested if statement into elif (#942)
-rw-r--r--yapf/third_party/yapf_diff/yapf_diff.py5
-rw-r--r--yapf/yapflib/reformatter.py26
2 files changed, 14 insertions, 17 deletions
diff --git a/yapf/third_party/yapf_diff/yapf_diff.py b/yapf/third_party/yapf_diff/yapf_diff.py
index 3377231..810a6a2 100644
--- a/yapf/third_party/yapf_diff/yapf_diff.py
+++ b/yapf/third_party/yapf_diff/yapf_diff.py
@@ -95,9 +95,8 @@ def main():
if args.regex is not None:
if not re.match('^%s$' % args.regex, filename):
continue
- else:
- if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE):
- continue
+ elif not re.match('^%s$' % args.iregex, filename, re.IGNORECASE):
+ continue
match = re.search(r'^@@.*\+(\d+)(,(\d+))?', line)
if match:
diff --git a/yapf/yapflib/reformatter.py b/yapf/yapflib/reformatter.py
index c5282b1..5695ed9 100644
--- a/yapf/yapflib/reformatter.py
+++ b/yapf/yapflib/reformatter.py
@@ -90,15 +90,14 @@ def Reformat(uwlines, verify=False, lines=None):
while state.next_token:
state.AddTokenToState(newline=False, dry_run=False)
- else:
- if not _AnalyzeSolutionSpace(state):
- # Failsafe mode. If there isn't a solution to the line, then just emit
- # it as is.
- state = format_decision_state.FormatDecisionState(uwline, indent_amt)
- state.MoveStateToNextToken()
- _RetainHorizontalSpacing(uwline)
- _RetainRequiredVerticalSpacing(uwline, prev_uwline, None)
- _EmitLineUnformatted(state)
+ elif not _AnalyzeSolutionSpace(state):
+ # Failsafe mode. If there isn't a solution to the line, then just emit
+ # it as is.
+ state = format_decision_state.FormatDecisionState(uwline, indent_amt)
+ state.MoveStateToNextToken()
+ _RetainHorizontalSpacing(uwline)
+ _RetainRequiredVerticalSpacing(uwline, prev_uwline, None)
+ _EmitLineUnformatted(state)
final_lines.append(uwline)
prev_uwline = uwline
@@ -404,12 +403,11 @@ def _FormatFinalLines(final_lines, verify):
if not tok.is_pseudo_paren:
formatted_line.append(tok.formatted_whitespace_prefix)
formatted_line.append(tok.value)
- else:
- if (not tok.next_token.whitespace_prefix.startswith('\n') and
+ elif (not tok.next_token.whitespace_prefix.startswith('\n') and
not tok.next_token.whitespace_prefix.startswith(' ')):
- if (tok.previous_token.value == ':' or
- tok.next_token.value not in ',}])'):
- formatted_line.append(' ')
+ if (tok.previous_token.value == ':' or
+ tok.next_token.value not in ',}])'):
+ formatted_line.append(' ')
formatted_code.append(''.join(formatted_line))
if verify: