aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <morbo@google.com>2021-11-08 02:24:12 -0800
committerBill Wendling <morbo@google.com>2021-11-08 02:24:12 -0800
commit7712742bdfcfa0f2c4f234eadbf85bce5643a125 (patch)
treea517110012985e39cb5485b59792e0dea6f835ac
parente9dd4e5f5c2f7630e760afedd9076c87b0e35296 (diff)
downloadyapf-7712742bdfcfa0f2c4f234eadbf85bce5643a125.tar.gz
Combine the "must_break_before" and "must_split" properties.
-rw-r--r--yapf/yapflib/format_token.py9
-rw-r--r--yapf/yapflib/reformatter.py2
-rw-r--r--yapf/yapflib/unwrapped_line.py5
3 files changed, 4 insertions, 12 deletions
diff --git a/yapf/yapflib/format_token.py b/yapf/yapflib/format_token.py
index 0f3cb60..6645585 100644
--- a/yapf/yapflib/format_token.py
+++ b/yapf/yapflib/format_token.py
@@ -130,7 +130,8 @@ class FormatToken(object):
self.container_elements = []
self.whitespace_prefix = ''
self.can_break_before = False
- self.must_break_before = False
+ self.must_break_before = pytree_utils.GetNodeAnnotation(
+ node, pytree_utils.Annotation.MUST_SPLIT, default=False)
self.total_length = 0
self.split_penalty = 0
@@ -264,12 +265,6 @@ class FormatToken(object):
pytree_utils.Annotation.NEWLINES)
@property
- def must_split(self):
- """Return true if the token requires a split before it."""
- return pytree_utils.GetNodeAnnotation(self.node,
- pytree_utils.Annotation.MUST_SPLIT)
-
- @property
def is_binary_op(self):
"""Token is a binary operator."""
return Subtype.BINARY_OPERATOR in self.subtypes
diff --git a/yapf/yapflib/reformatter.py b/yapf/yapflib/reformatter.py
index 91cad92..4626d75 100644
--- a/yapf/yapflib/reformatter.py
+++ b/yapf/yapflib/reformatter.py
@@ -84,7 +84,7 @@ def Reformat(uwlines, verify=False, lines=None):
_RetainRequiredVerticalSpacing(uwline, prev_uwline, lines)
_EmitLineUnformatted(state)
- elif _CanPlaceOnSingleLine(uwline) and not any(tok.must_split
+ elif _CanPlaceOnSingleLine(uwline) and not any(tok.must_break_before
for tok in uwline.tokens):
# The unwrapped line fits on one line.
while state.next_token:
diff --git a/yapf/yapflib/unwrapped_line.py b/yapf/yapflib/unwrapped_line.py
index 215d0cd..6cbd20e 100644
--- a/yapf/yapflib/unwrapped_line.py
+++ b/yapf/yapflib/unwrapped_line.py
@@ -118,8 +118,6 @@ class UnwrappedLine(object):
uwlines.append(uwline)
for uwline in uwlines:
- pytree_utils.SetNodeAnnotation(uwline.first.node,
- pytree_utils.Annotation.MUST_SPLIT, True)
uwline.first.previous_token = None
uwline.last.next_token = None
@@ -494,8 +492,7 @@ def _MustBreakBefore(prev_token, cur_token):
# reasonable assumption, because otherwise they should have written them
# all on the same line, or with a '+'.
return True
- return pytree_utils.GetNodeAnnotation(
- cur_token.node, pytree_utils.Annotation.MUST_SPLIT, default=False)
+ return cur_token.must_break_before
def _CanBreakBefore(prev_token, cur_token):