Skip to content

Commit 510ac63

Browse files
committed
Allow containers to wrap gracefully
And do not force breaks on commas in the middle of for comprehensions
1 parent 954933b commit 510ac63

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

yapf/yapflib/format_decision_state.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ def MustSplit(self):
213213
# Allow the fallthrough code to handle the closing bracket.
214214
if current != opening.matching_bracket:
215215
# If the container doesn't fit in the current line, must split
216-
return not self._ContainerFitsOnStartLine(opening)
216+
if (subtypes.COMP_FOR not in current.subtypes and
217+
not self._ContainerFitsOnStartLine(opening)):
218+
return True
217219

218220
if (self.stack[-1].split_before_closing_bracket and
219221
(current.value in '}]' and style.Get('SPLIT_BEFORE_CLOSING_BRACKET') or
@@ -557,9 +559,14 @@ def SurroundedByParens(token):
557559
return True
558560
else:
559561
# Split after the opening of a container if it doesn't fit on the
560-
# current line.
562+
# current line, including checking for wrapping.
561563
if not self._FitsOnLine(previous, previous.matching_bracket):
562-
return True
564+
arg_lengths = _CalculateArgLengths(previous)
565+
start_col = self.column + len(current.value) + len(previous.value)
566+
for length in arg_lengths:
567+
length += start_col
568+
if length > self.column_limit:
569+
return True
563570

564571
###########################################################################
565572
# Original Formatting Splitting

0 commit comments

Comments
 (0)