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

Allow joining of case statements in line_joiner.py #1211

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions yapf/yapflib/line_joiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ def CanMergeMultipleLines(lines, last_was_merged=False):
if lines[0].last.total_length < limit:
limit -= lines[0].last.total_length

if lines[0].first.value == 'if':
return _CanMergeLineIntoIfStatement(lines, limit)
if lines[0].first.value in {'if', 'case'}:
return _CanMergeLineIntoIfOrCaseStatement(lines, limit)
if last_was_merged and lines[0].first.value in {'elif', 'else'}:
return _CanMergeLineIntoIfStatement(lines, limit)
return _CanMergeLineIntoIfOrCaseStatement(lines, limit)

# TODO(morbo): Other control statements?

return False


def _CanMergeLineIntoIfStatement(lines, limit):
"""Determine if we can merge a short if-then statement into one line.
def _CanMergeLineIntoIfOrCaseStatement(lines, limit):
"""Determine if we can merge a short if-then or case statement into one line.

Two lines of an if-then statement can be merged if they were that way in the
original source, fit on the line without going over the column limit, and are
considered "simple" statements --- typically statements like 'pass',
Two lines of an if-then or case statement can be merged if they were that way
in the original source, fit on the line without going over the column limit,
and are considered "simple" statements --- typically statements like 'pass',
'continue', and 'break'.

Arguments:
Expand Down