Skip to content

Commit

Permalink
Allow containers to wrap gracefully
Browse files Browse the repository at this point in the history
And do not force breaks on commas in the middle of for comprehensions
  • Loading branch information
jesse-sony committed Oct 18, 2023
1 parent 954933b commit 510ac63
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions yapf/yapflib/format_decision_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ def MustSplit(self):
# Allow the fallthrough code to handle the closing bracket.
if current != opening.matching_bracket:
# If the container doesn't fit in the current line, must split
return not self._ContainerFitsOnStartLine(opening)
if (subtypes.COMP_FOR not in current.subtypes and
not self._ContainerFitsOnStartLine(opening)):
return True

if (self.stack[-1].split_before_closing_bracket and
(current.value in '}]' and style.Get('SPLIT_BEFORE_CLOSING_BRACKET') or
Expand Down Expand Up @@ -557,9 +559,14 @@ def SurroundedByParens(token):
return True
else:
# Split after the opening of a container if it doesn't fit on the
# current line.
# current line, including checking for wrapping.
if not self._FitsOnLine(previous, previous.matching_bracket):
return True
arg_lengths = _CalculateArgLengths(previous)
start_col = self.column + len(current.value) + len(previous.value)
for length in arg_lengths:
length += start_col
if length > self.column_limit:
return True

###########################################################################
# Original Formatting Splitting
Expand Down

0 comments on commit 510ac63

Please sign in to comment.