From 55dda50bd6ec20c4f523a96a2f96485b036c0dbe Mon Sep 17 00:00:00 2001 From: Marcel Simader Date: Sun, 17 Mar 2024 20:36:04 +0100 Subject: [PATCH] Allow joining of case statements in `line_joiner.py` Allows for the same rules that govern if-then statements to be applied to simple case statements. --- yapf/yapflib/line_joiner.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/yapf/yapflib/line_joiner.py b/yapf/yapflib/line_joiner.py index f0acd2f37..82df76956 100644 --- a/yapf/yapflib/line_joiner.py +++ b/yapf/yapflib/line_joiner.py @@ -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: